.chat-widget {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 18;
  width: min(380px, calc(100vw - 24px));
  color: var(--text);
}

.chat-toggle {
  position: static;
  min-width: 86px;
  min-height: 42px;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid color-mix(in srgb, var(--accent), transparent 35%);
  border-radius: 999px;
  padding: 9px 14px;
  background: color-mix(in srgb, var(--panel-2), black 8%);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.34);
  cursor: pointer;
}

.chat-toggle svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chat-toggle span {
  flex: 0 0 auto;
  white-space: nowrap;
}

.chat-panel {
  display: grid;
  grid-template-rows: 12px auto minmax(0, 1fr) auto;
  height: min(500px, calc(100vh - 44px));
  min-height: 360px;
  max-height: calc(100vh - 28px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel), black 6%);
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.44);
}

.chat-widget.is-collapsed {
  width: max-content;
}

.chat-widget.is-collapsed .chat-panel {
  display: none;
}

.chat-widget.is-collapsed .chat-toggle {
  display: inline-flex;
}

.chat-resize {
  width: 100%;
  height: 12px;
  border: 0;
  border-bottom: 1px solid color-mix(in srgb, var(--line), transparent 18%);
  padding: 0;
  background: color-mix(in srgb, var(--panel-2), black 8%);
  cursor: ns-resize;
  touch-action: none;
}

.chat-resize::before {
  content: "";
  display: block;
  width: 42px;
  height: 3px;
  margin: 4px auto 0;
  border-radius: 999px;
  background: color-mix(in srgb, var(--muted), transparent 45%);
}

.chat-resize:hover::before,
.chat-resize:focus-visible::before,
.chat-panel.is-resizing .chat-resize::before {
  background: color-mix(in srgb, var(--accent), transparent 20%);
}

.chat-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 13px 14px;
}

.chat-top h2 {
  font-size: 16px;
  line-height: 1.25;
}

.chat-top p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.chat-close {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
}

.chat-scroll-region {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: #111318;
}

.chat-messages {
  height: 100%;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: none;
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 12px 14px 54px;
  background: transparent;
  scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
  display: none;
}

.chat-scroll-bottom {
  position: absolute;
  left: 50%;
  bottom: 12px;
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid color-mix(in srgb, var(--accent), transparent 35%);
  border-radius: 999px;
  background: color-mix(in srgb, var(--panel-2), black 8%);
  color: var(--accent);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.36);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition:
    opacity 140ms ease,
    transform 140ms ease,
    background 140ms ease;
}

.chat-scroll-bottom.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, 0);
}

.chat-scroll-bottom:hover,
.chat-scroll-bottom:focus-visible {
  background: color-mix(in srgb, var(--accent), transparent 88%);
}

.chat-scroll-bottom svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chat-empty {
  margin: auto;
  color: var(--muted);
  font-size: 13px;
}

.chat-message {
  max-width: 88%;
  align-self: flex-start;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--panel);
  overflow-wrap: anywhere;
}

.chat-message.is-mine {
  align-self: flex-end;
  border-color: color-mix(in srgb, var(--accent), transparent 50%);
  background: color-mix(in srgb, var(--accent), transparent 91%);
}

.chat-message-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
}

.chat-message-meta strong {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-message p {
  color: var(--text);
  font-size: 13px;
  line-height: 1.42;
  white-space: pre-wrap;
}

.chat-form {
  display: grid;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding: 12px 14px 13px;
  background: var(--panel);
}

.chat-form input {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  background: #111318;
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

.chat-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 58px;
  gap: 8px;
}

.chat-input-row button {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #071512;
  font: inherit;
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
}

.chat-input-row button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.chat-form input:focus,
.chat-input-row button:focus-visible,
.chat-close:focus-visible,
.chat-toggle:focus-visible,
.chat-resize:focus-visible,
.chat-scroll-bottom:focus-visible {
  border-color: color-mix(in srgb, var(--accent), transparent 35%);
  outline: none;
}

.chat-status {
  min-height: 17px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.chat-status.is-error {
  color: var(--bad);
}

@media (max-width: 430px) {
  .chat-widget {
    right: 12px;
    bottom: 12px;
    width: calc(100vw - 24px);
  }

  .chat-panel {
    height: min(540px, calc(100vh - 24px));
    min-height: 360px;
    max-height: calc(100vh - 24px);
  }
}
