/**
 * BRUXÃO ASSISTENTE IA — widget flutuante (canto inferior direito)
 */

.bai-root {
  --bai-glow: hsl(var(--primary) / 0.5);
  position: fixed;
  right: max(0.75rem, env(safe-area-inset-right, 0px));
  bottom: max(0.75rem, env(safe-area-inset-bottom, 0px));
  z-index: 99968;
  font-family: inherit;
}

.bai-root:not([hidden]) {
  display: block;
}

.bai-fab {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.72rem 1rem 0.72rem 0.85rem;
  border: 1px solid hsl(var(--primary) / 0.45);
  border-radius: 999px;
  background: linear-gradient(135deg, hsl(var(--primary) / 0.92) 0%, hsl(var(--primary) / 0.72) 100%);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow:
    0 8px 28px -8px hsl(var(--primary) / 0.55),
    0 0 0 1px rgb(255 255 255 / 0.08) inset;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.bai-fab:hover {
  transform: translateY(-2px);
  box-shadow:
    0 12px 36px -10px hsl(var(--primary) / 0.65),
    0 0 0 1px rgb(255 255 255 / 0.12) inset;
}

.bai-fab__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.bai-fab__icon--close {
  display: none;
}

.bai-root.is-open .bai-fab__icon--open {
  display: none;
}

.bai-root.is-open .bai-fab__icon--close {
  display: flex;
}

.bai-fab__label {
  max-width: 0;
  overflow: hidden;
  opacity: 0;
  white-space: nowrap;
  transition: max-width 0.3s ease, opacity 0.25s ease;
}

.bai-fab:hover .bai-fab__label,
.bai-root.is-open .bai-fab__label {
  max-width: 8rem;
  opacity: 1;
}

.bai-panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + 0.65rem);
  width: min(calc(100vw - 1.5rem), 22.5rem);
  max-height: min(70vh, 32rem);
  display: flex;
  flex-direction: column;
  border-radius: calc(var(--radius) + 10px);
  border: 1px solid hsl(var(--primary) / 0.4);
  background: linear-gradient(
    168deg,
    rgb(var(--muted-solid) / 0.94) 0%,
    rgb(var(--background) / 0.98) 50%,
    rgb(var(--muted-solid) / 0.9) 100%
  );
  box-shadow:
    0 0 0 1px rgb(255 255 255 / 0.05) inset,
    0 24px 64px -20px rgb(0 0 0 / 0.75),
    0 0 72px -24px var(--bai-glow);
  backdrop-filter: blur(18px) saturate(1.2);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px) scale(0.96);
  transition:
    opacity 0.32s cubic-bezier(0.22, 1, 0.36, 1),
    transform 0.32s cubic-bezier(0.22, 1, 0.36, 1),
    visibility 0.32s step-end;
}

.bai-root.is-open .bai-panel {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
  transition:
    opacity 0.32s cubic-bezier(0.22, 1, 0.36, 1),
    transform 0.32s cubic-bezier(0.22, 1, 0.36, 1),
    visibility 0s;
}

.bai-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 0.9rem;
  border-bottom: 1px solid rgb(255 255 255 / 0.06);
  background: hsl(var(--primary) / 0.08);
}

.bai-header__brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}

.bai-header__avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.65rem;
  background: hsl(var(--primary) / 0.2);
  color: hsl(var(--primary));
  flex-shrink: 0;
}

.bai-header__title {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  line-height: 1.2;
  color: hsl(var(--foreground));
}

.bai-header__status {
  margin: 0.15rem 0 0;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.68rem;
  color: rgb(var(--muted-foreground));
}

.bai-header__dot {
  width: 0.42rem;
  height: 0.42rem;
  border-radius: 50%;
  background: #23a559;
  box-shadow: 0 0 8px rgb(35 165 89 / 0.75);
  animation: bai-dot-pulse 1.8s ease-in-out infinite;
}

@keyframes bai-dot-pulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.65;
    transform: scale(0.9);
  }
}

.bai-header__close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border: 1px solid rgb(255 255 255 / 0.08);
  border-radius: 0.5rem;
  background: rgb(255 255 255 / 0.04);
  color: rgb(var(--muted-foreground));
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
  flex-shrink: 0;
}

.bai-header__close:hover {
  background: rgb(255 255 255 / 0.08);
  color: hsl(var(--foreground));
}

.bai-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  scroll-behavior: smooth;
}

.bai-msg {
  max-width: 92%;
  padding: 0.62rem 0.78rem;
  border-radius: 0.75rem;
  font-size: 0.82rem;
  line-height: 1.45;
  word-break: break-word;
}

.bai-msg--bot {
  align-self: flex-start;
  background: rgb(255 255 255 / 0.05);
  border: 1px solid rgb(255 255 255 / 0.06);
  color: hsl(var(--foreground));
}

.bai-msg--user {
  align-self: flex-end;
  background: hsl(var(--primary) / 0.22);
  border: 1px solid hsl(var(--primary) / 0.35);
  color: hsl(var(--foreground));
}

.bai-msg a {
  color: hsl(var(--primary));
  text-decoration: underline;
  text-underline-offset: 2px;
}

.bai-msg a:hover {
  opacity: 0.85;
}

.bai-msg--typing {
  display: flex;
  align-items: center;
  gap: 0.28rem;
  padding: 0.72rem 0.85rem;
}

.bai-msg--typing span {
  width: 0.38rem;
  height: 0.38rem;
  border-radius: 50%;
  background: hsl(var(--primary) / 0.7);
  animation: bai-typing 1.2s ease-in-out infinite;
}

.bai-msg--typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.bai-msg--typing span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes bai-typing {
  0%,
  80%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

.bai-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0 0.85rem 0.65rem;
}

.bai-quick:empty {
  display: none;
}

.bai-quick__btn {
  padding: 0.35rem 0.62rem;
  border-radius: 999px;
  border: 1px solid hsl(var(--primary) / 0.35);
  background: hsl(var(--primary) / 0.1);
  color: hsl(var(--foreground));
  font-size: 0.68rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.bai-quick__btn:hover {
  background: hsl(var(--primary) / 0.18);
  border-color: hsl(var(--primary) / 0.5);
}

.bai-form {
  display: flex;
  align-items: flex-end;
  gap: 0.45rem;
  padding: 0.65rem 0.85rem 0.85rem;
  border-top: 1px solid rgb(255 255 255 / 0.06);
  background: rgb(0 0 0 / 0.12);
}

.bai-input {
  flex: 1;
  min-height: 2.35rem;
  max-height: 5.5rem;
  resize: none;
  padding: 0.55rem 0.72rem;
  border-radius: 0.65rem;
  border: 1px solid rgb(255 255 255 / 0.08);
  background: rgb(255 255 255 / 0.04);
  color: hsl(var(--foreground));
  font-size: 0.82rem;
  line-height: 1.4;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.bai-input::placeholder {
  color: rgb(var(--muted-foreground));
}

.bai-input:focus {
  border-color: hsl(var(--primary) / 0.5);
  box-shadow: 0 0 0 2px hsl(var(--primary) / 0.15);
}

.bai-send {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.35rem;
  height: 2.35rem;
  border: none;
  border-radius: 0.65rem;
  background: hsl(var(--primary));
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.bai-send:hover:not(:disabled) {
  transform: scale(1.04);
}

.bai-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (min-width: 641px) {
  .bai-root {
    right: max(1rem, env(safe-area-inset-right, 0px));
    bottom: max(1rem, env(safe-area-inset-bottom, 0px));
  }

  .bai-panel {
    width: 22.5rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .bai-fab,
  .bai-panel,
  .bai-header__dot,
  .bai-msg--typing span {
    animation: none;
    transition: none;
  }
}