.mt-chat {
  --mt-chat-bg: #101423;
  --mt-chat-ink: #f4f0fa;
  --mt-chat-dim: #b9b8cd;
  --mt-chat-line: #292a40;
  --mt-chat-action: #66e7f4;
  --mt-chat-mark: #f7cd46;
  position: fixed;
  inset-inline-start: clamp(.75rem, 2vw, 1.6rem);
  inset-block-end: max(.75rem, env(safe-area-inset-bottom));
  z-index: 30;
  color: var(--mt-chat-ink);
  font: 500 1.2rem/1.35 'Barlow Condensed', sans-serif;
  text-align: start;
}

.mt-chat__toggle, .mt-chat__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  min-height: 44px;
  color: var(--mt-chat-action);
  font: inherit;
  cursor: pointer;
}

.mt-chat__toggle {
  padding: .45rem .95rem;
  border: 1px solid currentColor;
  border-radius: .6rem .2rem .6rem .2rem;
  background: var(--mt-chat-bg);
  box-shadow: 0 .15rem .8rem #66e7f435;
}

.mt-chat__toggle[hidden], .mt-chat__panel:not([open]) { display: none; }

.mt-chat svg {
  width: 1.4rem;
  height: 1.4rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

.mt-chat__panel {
  position: absolute;
  inset: auto auto 0 0;
  display: grid;
  grid-template-rows: auto minmax(4rem, 1fr) auto auto;
  width: min(23rem, calc(100vw - 1.5rem));
  height: min(34rem, calc(100dvh - 2.5rem));
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid #ff61bc;
  border-radius: .8rem;
  background: var(--mt-chat-bg);
  color: var(--mt-chat-ink);
  box-shadow: 0 .65rem 2rem #070b16;
  color-scheme: dark;
}

.mt-chat__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  padding: .25rem .8rem .25rem 1rem;
  border-block-end: 1px solid var(--mt-chat-line);
}

.mt-chat__header h2 {
  margin: 0;
  color: var(--mt-chat-mark);
  font: 400 2rem/1.15 Yellowtail, cursive;
}

.mt-chat__close {
  min-width: 44px;
  border: 0;
  border-radius: .25rem;
  background: transparent;
}

.mt-chat__history {
  min-width: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: .8rem 1rem;
}

.mt-chat__history > p { margin: 0 0 .65rem; }

.mt-chat__message {
  width: fit-content;
  max-width: 95%;
  margin: 0 0 .65rem;
  padding: .45rem .7rem;
  border: 1px solid var(--mt-chat-line, #292a40);
  border-radius: .4rem;
}

.mt-chat__message--own { margin-inline-start: auto; }
.mt-chat__message strong { color: var(--mt-chat-mark, #f7cd46); }
.mt-chat__message time { margin-inline-start: .55rem; color: var(--mt-chat-dim, #b9b8cd); font-size: .9rem; }
.mt-chat__message p { margin: .25rem 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }

.mt-chat__form { padding: .55rem 1rem .2rem; }
.mt-chat__form label { display: block; margin-block-end: .25rem; }
.mt-chat__form textarea {
  display: block;
  box-sizing: border-box;
  width: 100%;
  padding: .4rem .55rem;
  border: 1px solid var(--mt-chat-action, #66e7f4);
  border-radius: .25rem;
  background: #070b16;
  color: #f4f0fa;
  font: inherit;
  resize: vertical;
}
.mt-chat .mt-chat__form textarea { max-height: 100px; }

.mt-chat__form button {
  margin-block-start: .45rem;
  min-height: 44px;
  padding: .3rem .8rem;
  border: 1px solid currentColor;
  border-radius: .4rem;
  color: var(--mt-chat-mark, #f7cd46);
  background: #101423;
  font: inherit;
  cursor: pointer;
}

.mt-chat__form button:disabled { opacity: .65; cursor: wait; }
.mt-chat__status, .mt-chat__privacy { margin: .15rem 0 0; color: var(--mt-chat-dim, #b9b8cd); font-size: 1rem; }
.mt-chat__status:empty { display: none; }
.mt-chat__privacy { padding: 0 1rem .55rem; }
.mt-chat__privacy a { color: var(--mt-chat-action); text-underline-offset: .15em; }
.mt-chat :focus-visible { outline: 2px solid var(--mt-chat-action); outline-offset: 2px; }
.mt-chat__history:focus-visible { outline-offset: -3px; }
.mt-chat-admin .mt-chat__history { min-height: 12rem; max-height: 55dvh; padding: 1rem; border: 1px solid var(--mt-chat-line, #292a40); border-radius: .4rem; }
.mt-chat-admin .mt-chat__form { padding-inline: 0; }

@media (max-width: 760px) {
  body:is([data-mt-surface="home"], [data-mt-surface="product"]) .mt-chat__toggle {
    position: relative;
    justify-content: center;
    width: 2.75rem;
    height: 2.75rem;
    padding: 0;
  }

  body:is([data-mt-surface="home"], [data-mt-surface="product"]) .mt-chat__toggle span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}

@media (max-width: 700px), (pointer: coarse) {
  .mt-chat--inline-mobile {
    position: static;
    text-align: center;
  }

  .mt-chat--inline-mobile .mt-chat__toggle {
    margin-block-end: 1.5rem;
  }

  .mt-chat--inline-mobile .mt-chat__toggle[aria-expanded="true"] {
    display: inline-flex;
    visibility: hidden;
  }

  .mt-chat--inline-mobile .mt-chat__panel {
    position: fixed;
    inset: auto max(.75rem, env(safe-area-inset-right)) max(.75rem, env(safe-area-inset-bottom)) max(.75rem, env(safe-area-inset-left));
    z-index: 30;
    width: auto;
    max-width: 23rem;
    margin-inline: auto;
    text-align: start;
  }
}

@media (max-height: 480px) {
  .mt-chat__panel { height: calc(100dvh - 1.5rem); }
  .mt-chat__form textarea { height: 2.25rem; resize: none; }
}

.mt-chat [hidden] { display: none; }
.mt-chat__access { grid-row: 2 / 4; min-height: 0; overflow-y: auto; padding-block-start: .25rem; }
.mt-chat__access h3 { margin: .4rem 0 .45rem; color: var(--mt-chat-ink); font: 400 1.3rem/1.25 'Righteous', sans-serif; }
.mt-chat__access p { margin: 0 0 1rem; color: var(--mt-chat-dim); }
.mt-chat__access input {
  display: block;
  box-sizing: border-box;
  width: 100%;
  min-height: 44px;
  padding: .35rem .55rem;
  border: 1px solid var(--mt-chat-action);
  border-radius: .25rem;
  background: #070b16;
  color: var(--mt-chat-ink);
  font: inherit;
}
.mt-chat__footer { grid-row: 4; display: flex; flex-wrap: wrap; align-items: center; column-gap: .85rem; padding: 0 1rem .45rem; }
.mt-chat__footer .mt-chat__status { flex: 0 0 100%; }
.mt-chat__footer .mt-chat__privacy { padding: 0; }
.mt-chat .mt-chat__text-button {
  min-height: 44px;
  margin: 0;
  padding: .3rem 0;
  border: 0;
  background: transparent;
  color: var(--mt-chat-action);
  font: 500 1rem/1.2 'Barlow Condensed', sans-serif;
  text-align: start;
  text-decoration: underline;
  text-underline-offset: .15em;
  cursor: pointer;
}
.mt-chat__access .mt-chat__text-button { display: block; }
.mt-chat__access .mt-chat__text-button[hidden] { display: none; }
.mt-chat__message--automatic { border-style: dashed; }

.mt-chat__panel:not([data-stage="chat"]) {
  height: auto;
  max-height: calc(100dvh - 1.5rem);
  grid-template-rows: auto minmax(0, 1fr) auto;
}
.mt-chat__panel:not([data-stage="chat"]) .mt-chat__access { grid-row: 2; padding-block-end: .6rem; }
.mt-chat__panel:not([data-stage="chat"]) .mt-chat__footer { grid-row: 3; }
