.site-chat {
  --chat-gutter: clamp(.75rem, 2.3vw, 1.5rem);
  position: fixed;
  z-index: 8;
  right: max(var(--chat-gutter), env(safe-area-inset-right));
  bottom: max(var(--chat-gutter), env(safe-area-inset-bottom));
}

.chat-launcher, .chat-close, .chat-quick-button {
  font: 700 .9375rem/1.15 var(--body);
  cursor: pointer;
}

.chat-launcher {
  display: inline-flex;
  align-items: center;
  gap: .6rem;
  min-height: 3.1rem;
  padding: .65rem 1.05rem;
  border: 1px solid #efffb7;
  border-radius: .35rem;
  background: var(--lime);
  color: #141907;
  box-shadow: 0 .35rem 1.25rem #0007, 0 0 1.15rem #dbff5638;
}

.chat-launcher[hidden] { display: none; }
.chat-launcher:hover { background: #eaff9b; }

.chat-bubble {
  position: relative;
  display: inline-block;
  width: 1rem;
  height: .8rem;
  border: 1.5px solid currentColor;
  border-radius: .16rem;
}

.chat-bubble::after {
  content: "";
  position: absolute;
  left: .18rem;
  bottom: -.22rem;
  width: .26rem;
  height: .23rem;
  border-left: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: skewY(-31deg);
  background: var(--chat-icon-surface, var(--lime));
}

.chat-launcher:hover .chat-bubble { --chat-icon-surface: #eaff9b; }

.chat-panel {
  position: absolute;
  inset: auto 0 calc(100% + .7rem) auto;
  width: min(24rem, calc(100vw - var(--chat-gutter) * 2));
  height: min(32rem, calc(100vh - 6rem));
  height: min(32rem, calc(100dvh - 6rem - env(safe-area-inset-bottom)));
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid #596637;
  border-radius: .45rem;
  background: #10150d;
  color: var(--type);
  box-shadow: 0 .85rem 3rem #000b;
}

.chat-panel[open] { display: flex; flex-direction: column; }

.chat-header {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .75rem .85rem;
  border-bottom: 1px solid #364025;
  background: linear-gradient(115deg, #273319, #171e10 75%);
}

.chat-header-mark {
  --chat-icon-surface: #182313;
  display: grid;
  place-items: center;
  width: 2.15rem;
  height: 2.15rem;
  flex: 0 0 auto;
  border: 1px solid #657d39;
  border-radius: .22rem;
  background: var(--chat-icon-surface);
  color: var(--lime);
}

.chat-header h2 {
  font: 700 1.2rem/1.2 var(--heading);
  letter-spacing: -.035em;
}

.chat-close {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 2.75rem;
  height: 2.75rem;
  margin-left: auto;
  padding: 0;
  border: 1px solid transparent;
  border-radius: .2rem;
  background: transparent;
  color: var(--type);
  font-size: 1.5rem;
  font-weight: 400;
}

.chat-close:hover { background: #25321b; color: var(--lime); }

.chat-messages {
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  gap: .7rem;
  min-height: 0;
  padding: .9rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-color: #4b5a35 transparent;
}

.chat-messages:focus-visible { outline-offset: -3px; }

.chat-message {
  max-width: 87%;
  flex: 0 0 auto;
  padding: .62rem .78rem;
  border: 1px solid #344129;
  border-radius: .35rem;
  font-size: .98rem;
  line-height: 1.46;
  overflow-wrap: anywhere;
}

.chat-message p { white-space: pre-wrap; }
.chat-message-assistant { align-self: flex-start; background: #192119; }
.chat-message-visitor { align-self: flex-end; background: #2c391a; border-color: #576a32; }

.chat-answer-links {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem .85rem;
  margin-top: .48rem;
}

.chat-answer-link {
  color: var(--lime);
  font-weight: 650;
  text-decoration: underline;
  text-underline-offset: .18em;
}

.chat-answer-link:hover { color: #f0ffc1; }

.chat-quick {
  display: flex;
  gap: .4rem;
  flex-wrap: wrap;
  padding: .15rem .85rem .65rem;
}

.chat-quick-button {
  min-height: 2rem;
  padding: .32rem .62rem;
  border: 1px solid #536338;
  border-radius: .26rem;
  background: #1a2413;
  color: #e2f6ae;
  font-size: .85rem;
}

.chat-quick-button:hover { background: #303f1d; }

.chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: stretch;
  gap: .55rem;
  padding: .7rem .85rem .85rem;
  border-top: 1px solid #364025;
  background: #131a10;
}

.chat-form input {
  width: 100%;
  min-width: 0;
  padding: .62rem .68rem;
  border: 1px solid #596747;
  border-radius: .22rem;
  background: #0b1009;
  color: var(--type);
  font: 1rem/1.3 var(--body);
}

.chat-form input::placeholder { color: #b1b9a6; }
.chat-form .chat-send { min-height: 2.65rem; padding-inline: .82rem; }

.chat-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

@media (max-height: 540px) {
  .chat-header { padding-block: .42rem; }
  .chat-quick { flex-wrap: nowrap; overflow-x: auto; }
  .chat-quick-button { flex: 0 0 auto; }
  .chat-form { padding-block: .5rem; }
}
