.bb-chat {
  position: fixed;
  z-index: 30;
  right: 1rem;
  bottom: calc(1rem + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.6rem;
  max-width: calc(100vw - 1.5rem);
  font-family: var(--font-sans), Outfit, sans-serif;
  color: var(--foreground);
}

.bb-chat[hidden] {
  display: none;
}

.bb-chat-nudge,
.bb-chat-panel {
  width: min(22rem, calc(100vw - 1.5rem));
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--card);
  box-shadow: 0 12px 40px color-mix(in oklch, var(--foreground) 12%, transparent);
}

.bb-chat-nudge {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin: 0;
  padding: 0.8rem 0.7rem 0.8rem 0.95rem;
  font-size: 0.92rem;
  line-height: 1.4;
}

.bb-chat-nudge[hidden],
.bb-chat-panel[hidden] {
  display: none;
}

.bb-chat-nudge p {
  margin: 0;
  flex: 1;
}

.bb-chat-icon,
.bb-chat-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.bb-chat-close {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 999px;
  font-size: 1.1rem;
  line-height: 1;
}

.bb-chat-close:hover,
.bb-chat-close:focus-visible,
.bb-chat-bubble:focus-visible,
.bb-chat-send:focus-visible,
.bb-chat-form input:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

.bb-chat-bubble {
  width: 3rem;
  height: 3rem;
  border: 0;
  border-radius: 999px;
  background: var(--primary);
  color: var(--primary-foreground);
  box-shadow: 0 8px 24px color-mix(in oklch, var(--primary) 35%, transparent);
  cursor: pointer;
}

.bb-chat-bubble:hover {
  filter: brightness(1.08);
}

.bb-chat-panel {
  display: flex;
  flex-direction: column;
  max-height: min(28rem, calc(100dvh - 7rem));
  overflow: hidden;
}

.bb-chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.75rem 0.7rem 0.75rem 0.95rem;
  border-bottom: 1px solid var(--border);
}

.bb-chat-head h2 {
  margin: 0;
  font-family: var(--font-sans), system-ui, sans-serif;
  font-size: 1.05rem;
  font-weight: 560;
}

.bb-chat-log {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  min-height: 7rem;
  padding: 0.85rem 0.95rem;
  overflow: auto;
  font-size: 0.92rem;
  line-height: 1.45;
}

.bb-chat-log p {
  margin: 0;
  max-width: 95%;
  padding: 0.55rem 0.7rem;
  border-radius: 0.8rem;
}

.bb-chat-log .bb-user {
  align-self: flex-end;
  background: var(--primary);
  color: var(--primary-foreground);
}

.bb-chat-log .bb-bot {
  align-self: flex-start;
  background: var(--secondary);
}

.bb-chat-form {
  display: flex;
  gap: 0.4rem;
  padding: 0.7rem;
  border-top: 1px solid var(--border);
}

.bb-chat-form input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--input);
  border-radius: 999px;
  background: var(--background);
  color: inherit;
  padding: 0.55rem 0.8rem;
  font: inherit;
}

.bb-chat-send {
  border: 0;
  border-radius: 999px;
  background: var(--primary);
  color: var(--primary-foreground);
  padding: 0.55rem 0.85rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.bb-chat-send:disabled {
  opacity: 0.6;
  cursor: default;
}

.bb-chat-note {
  margin: 0;
  padding: 0 0.95rem 0.7rem;
  color: var(--muted-foreground);
  font-size: 0.75rem;
}

.bb-chat-note a {
  color: var(--brass);
}

@media (max-width: 640px) {
  .bb-chat {
    right: 0.75rem;
    bottom: calc(0.75rem + env(safe-area-inset-bottom));
  }

  .bb-chat-bubble {
    width: 2.75rem;
    height: 2.75rem;
  }

  .bb-chat-panel,
  .bb-chat-nudge {
    width: min(22rem, calc(100vw - 1.5rem));
  }

  .bb-chat-panel {
    max-height: min(24rem, calc(100dvh - 6.5rem));
  }
}

@media (prefers-reduced-motion: no-preference) {
  .bb-chat-nudge,
  .bb-chat-panel {
    animation: bb-chat-in 180ms ease-out;
  }
}

@keyframes bb-chat-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
