.ba-chat,
.ba-chat * {
  box-sizing: border-box;
}

.ba-chat {
  position: fixed;
  right: 16px;
  bottom: 84px;
  z-index: 9998;
  color: var(--ink, #1f2933);
  font-family: var(--body, system-ui, sans-serif);
  line-height: 1.45;
}

.ba-chat__toggle {
  display: grid;
  width: 56px;
  height: 56px;
  margin-left: auto;
  padding: 0;
  place-items: center;
  border: 2px solid var(--paper, #ffffff);
  border-radius: 50%;
  background: var(--accent, #d97706);
  box-shadow: var(--shadow, 0 12px 32px rgb(0 0 0 / 20%));
  color: var(--paper, #ffffff);
  font-family: var(--head, system-ui, sans-serif);
  font-size: 1.35rem;
  font-weight: 800;
  cursor: pointer;
}

.ba-chat__panel {
  display: flex;
  width: min(380px, calc(100vw - 32px));
  height: min(520px, calc(100vh - 172px));
  min-height: 320px;
  margin-bottom: 12px;
  overflow: hidden;
  flex-direction: column;
  border: 1px solid var(--line, #d6d3cd);
  border-radius: var(--radius, 18px);
  background: var(--bg, #f7f5f0);
  box-shadow: var(--shadow, 0 12px 32px rgb(0 0 0 / 20%));
}

.ba-chat__panel[hidden] {
  display: none;
}

.ba-chat__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 58px;
  padding: 10px 12px 10px 18px;
  border-bottom: 1px solid var(--line, #d6d3cd);
  background: var(--paper, #ffffff);
}

.ba-chat__title {
  font-family: var(--head, system-ui, sans-serif);
  font-size: 1.05rem;
  font-weight: 750;
}

.ba-chat__close {
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink, #1f2933);
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
}

.ba-chat__thread {
  min-height: 0;
  padding: 18px 14px;
  overflow-x: hidden;
  overflow-y: auto;
  flex: 1;
  overscroll-behavior: contain;
}

.ba-chat__row {
  display: flex;
  margin: 0 0 10px;
}

.ba-chat__row--user {
  justify-content: flex-end;
}

.ba-chat__bubble {
  max-width: 84%;
  padding: 10px 13px;
  overflow-wrap: anywhere;
  border: 1px solid var(--line, #d6d3cd);
  border-radius: var(--radius, 18px);
  background: var(--paper, #ffffff);
  white-space: pre-wrap;
}

.ba-chat__row--user .ba-chat__bubble {
  border-color: var(--accent, #d97706);
  background: var(--accent, #d97706);
  color: var(--paper, #ffffff);
}

.ba-chat__form {
  padding: 12px 14px 10px;
  border-top: 1px solid var(--line, #d6d3cd);
  background: var(--paper, #ffffff);
}

.ba-chat__controls {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.ba-chat__input {
  width: 100%;
  min-height: 44px;
  max-height: 96px;
  padding: 10px 12px;
  resize: none;
  overflow-y: auto;
  flex: 1;
  border: 1px solid var(--line, #d6d3cd);
  border-radius: calc(var(--radius, 18px) * .7);
  outline: 0;
  background: var(--bg, #f7f5f0);
  color: var(--ink, #1f2933);
  font: inherit;
}

.ba-chat__input::placeholder {
  color: var(--muted, #6b7280);
}

.ba-chat__send {
  min-height: 44px;
  padding: 9px 14px;
  border: 1px solid var(--accent, #d97706);
  border-radius: calc(var(--radius, 18px) * .7);
  background: var(--accent, #d97706);
  color: var(--paper, #ffffff);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.ba-chat__note {
  margin: 8px 2px 0;
  color: var(--muted, #6b7280);
  font-size: .72rem;
  line-height: 1.35;
}

.ba-chat button:focus-visible,
.ba-chat textarea:focus-visible {
  outline: 3px solid var(--accent2, #0f766e);
  outline-offset: 3px;
}

.ba-chat button:disabled,
.ba-chat textarea:disabled {
  cursor: not-allowed;
  opacity: .65;
}

.ba-chat__typing {
  display: flex;
  min-width: 58px;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.ba-chat__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted, #6b7280);
  animation: ba-chat-bounce 1.1s infinite ease-in-out;
}

.ba-chat__dot:nth-child(2) {
  animation-delay: .14s;
}

.ba-chat__dot:nth-child(3) {
  animation-delay: .28s;
}

@keyframes ba-chat-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-4px); }
}

@media (prefers-reduced-motion: reduce) {
  .ba-chat__dot {
    animation: none;
  }
}

@media (max-width: 600px) {
  .ba-chat__panel {
    width: calc(100vw - 24px);
    height: calc(100dvh - 112px);
    max-height: none;
    min-height: 0;
    margin-bottom: 8px;
    border-radius: var(--radius, 18px);
  }

  .ba-chat {
    right: 12px;
    bottom: 84px;
  }
}
