.bt-chat {
  --chat-line: color-mix(in srgb, var(--border, rgba(255,255,255,.12)) 74%, transparent);
  --chat-panel: color-mix(in srgb, var(--card, #171717) 92%, transparent);
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(280px, 1fr) auto auto auto;
  min-height: 520px;
  overflow: hidden;
  border: 1px solid var(--chat-line);
  border-radius: 24px;
  background: var(--chat-panel);
  box-shadow: 0 20px 60px rgba(0,0,0,.18);
}

.community-chat-screen {
  min-height: calc(100dvh - 190px);
  padding: 0 16px 100px;
}

.community-chat-loading {
  padding: 32px;
  color: var(--muted);
  text-align: center;
}

.bt-chat-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--chat-line);
  background: color-mix(in srgb, var(--chat-panel) 94%, transparent);
}

.bt-chat-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.bt-chat-heading > div {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.bt-chat-heading b,
.bt-chat-heading small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bt-chat-heading b { color: var(--text); font-size: 14px; }
.bt-chat-heading small { color: var(--muted); font-size: 11px; }

.bt-chat-live-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #4ccf86;
  box-shadow: 0 0 0 4px rgba(76,207,134,.12), 0 0 18px rgba(76,207,134,.35);
}

.bt-chat-search { width: min(260px, 38%); }

.bt-chat-search-input,
.bt-chat-input {
  width: 100%;
  border: 1px solid var(--chat-line);
  border-radius: 13px;
  background: color-mix(in srgb, var(--bg, #0d0d0d) 78%, transparent);
  color: var(--text);
  font: inherit;
  outline: none;
}

.bt-chat-search-input { height: 38px; padding: 0 12px; font-size: 12px; }
.bt-chat-input { min-height: 44px; max-height: 132px; resize: none; padding: 11px 13px; line-height: 1.45; }
.bt-chat-search-input:focus,
.bt-chat-input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px color-mix(in srgb, var(--gold) 18%, transparent); }

.bt-chat-stream {
  position: relative;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 10px 14px 18px;
  scrollbar-width: thin;
}

.bt-chat-list { display: grid; gap: 3px; }

.bt-chat-older {
  display: block;
  margin: 4px auto 14px;
  border: 1px solid var(--chat-line);
  border-radius: 999px;
  padding: 7px 13px;
  background: transparent;
  color: var(--muted);
  font: 600 11px/1 inherit;
  cursor: pointer;
}

.bt-chat-message {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 10px;
  padding: 10px 8px;
  border-radius: 15px;
}

.bt-chat-message:hover,
.bt-chat-message:focus-within { background: color-mix(in srgb, var(--text) 4%, transparent); }

.bt-chat-avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid color-mix(in srgb, var(--gold) 30%, var(--chat-line));
  border-radius: 11px;
  background: color-mix(in srgb, var(--gold) 9%, var(--bg));
  color: var(--gold);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .04em;
}

.bt-chat-message-content { min-width: 0; }
.bt-chat-meta { display: flex; align-items: baseline; gap: 7px; min-width: 0; }
.bt-chat-meta b { overflow: hidden; color: var(--text); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.bt-chat-meta time { margin-left: auto; color: var(--faint, var(--muted)); font-size: 10px; white-space: nowrap; }

.bt-chat-role {
  border: 1px solid color-mix(in srgb, var(--gold) 34%, transparent);
  border-radius: 999px;
  padding: 2px 6px;
  background: color-mix(in srgb, var(--gold) 9%, transparent);
  color: var(--gold);
  font-size: 8px;
  font-weight: 800;
  letter-spacing: .07em;
  text-transform: uppercase;
}

.bt-chat-body {
  margin: 4px 0 0;
  color: color-mix(in srgb, var(--text) 91%, var(--muted));
  font-size: 13px;
  line-height: 1.5;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.bt-chat-quoted {
  margin-top: 5px;
  overflow: hidden;
  border-left: 2px solid color-mix(in srgb, var(--gold) 55%, transparent);
  padding: 4px 8px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bt-chat-actions { display: flex; flex-wrap: wrap; gap: 2px; margin: 5px 0 -3px -5px; opacity: .55; }
.bt-chat-message:hover .bt-chat-actions,
.bt-chat-message:focus-within .bt-chat-actions { opacity: 1; }
.bt-chat-action {
  min-height: 28px;
  border: 0;
  border-radius: 8px;
  padding: 0 6px;
  background: transparent;
  color: var(--muted);
  font: 650 10px/1 inherit;
  cursor: pointer;
}
.bt-chat-action:hover,
.bt-chat-action:focus-visible { background: color-mix(in srgb, var(--text) 7%, transparent); color: var(--text); outline: none; }
.bt-chat-action.is-danger { color: #e48c82; }

.bt-chat-composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 9px;
  padding: 12px 14px;
  border-top: 1px solid var(--chat-line);
  background: color-mix(in srgb, var(--chat-panel) 96%, transparent);
}

.bt-chat-send {
  min-width: 68px;
  height: 44px;
  border: 0;
  border-radius: 13px;
  background: var(--gold);
  color: #111;
  font: 800 11px/1 inherit;
  cursor: pointer;
}

.bt-chat-send:disabled { cursor: wait; opacity: .55; }

.bt-chat-replybar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 15px;
  border-top: 1px solid var(--chat-line);
  color: var(--muted);
  font-size: 10px;
}
.bt-chat-replybar span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bt-chat-replybar button { border: 0; background: transparent; color: var(--gold); cursor: pointer; }

.bt-chat-status { min-height: 20px; padding: 2px 15px 8px; color: var(--muted); font-size: 10px; }
.bt-chat-status.is-error { color: #e48c82; }
.bt-chat-status.is-ok { color: #6fdca0; }

.bt-chat-jump {
  position: absolute;
  right: 18px;
  bottom: 92px;
  z-index: 3;
  border: 1px solid color-mix(in srgb, var(--gold) 42%, transparent);
  border-radius: 999px;
  padding: 8px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  color: var(--gold);
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
  font: 750 10px/1 inherit;
  cursor: pointer;
}

.bt-chat-empty {
  display: grid;
  place-items: center;
  gap: 7px;
  min-height: 220px;
  padding: 30px;
  color: var(--text);
  text-align: center;
}
.bt-chat-empty small { max-width: 320px; color: var(--muted); }
.bt-chat-empty.is-error b { color: #e48c82; }

@media (max-width: 620px) {
  .bt-chat { min-height: calc(100dvh - 210px); border-radius: 20px; }
  .bt-chat-toolbar { align-items: stretch; flex-direction: column; gap: 10px; }
  .bt-chat-search { width: 100%; }
  .bt-chat-message { grid-template-columns: 32px minmax(0, 1fr); padding-inline: 2px; }
  .bt-chat-avatar { width: 31px; height: 31px; }
  .bt-chat-actions { opacity: .78; }
}

@media (prefers-reduced-motion: reduce) {
  .bt-chat-jump { scroll-behavior: auto; }
}

