.agent-chat-fab {
  position: fixed;
  right: 24px;
  /* Sit above the page-nav dock (Back + Top tabs at bottom: 24px) */
  bottom: calc(24px + 2.5rem + 10px);
  z-index: 250;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: 999px;
  border: 1.5px solid rgba(255, 255, 255, 0.45);
  background: rgba(0, 0, 0, 0.42);
  color: var(--white);
  font-family: inherit;
  font-size: clamp(0.82rem, 1vw, 1rem);
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity 0.28s ease, visibility 0.28s ease, transform 0.28s ease, background 0.25s ease, border-color 0.25s ease;
}

.agent-chat-fab.is-enter-visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0);
}

.agent-chat-fab svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.agent-chat-fab:hover {
  background: rgba(0, 200, 83, 0.92);
  border-color: var(--green);
  color: var(--white);
  transform: translateY(-1px);
}

.agent-chat-fab.is-enter-visible:hover {
  transform: translateY(-1px);
}

.agent-chat-fab.is-open {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(12px);
}

.agent-chat {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: min(380px, calc(100vw - 32px));
  max-height: min(560px, calc(100vh - 120px));
  display: flex;
  flex-direction: column;
  border-radius: 16px;
  background: var(--white);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.22);
  z-index: 300;
  overflow: hidden;
  transform: translateY(16px) scale(0.98);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease, transform 0.28s ease;
}

.agent-chat.is-open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
  height: min(560px, calc(100vh - 120px));
}

.agent-chat__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  background: linear-gradient(135deg, var(--green), var(--green-hover));
  color: var(--white);
}

.agent-chat__agent {
  display: flex;
  align-items: center;
  gap: 12px;
}

.agent-chat__avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.18);
  font-weight: 700;
  font-size: 0.95rem;
}

.agent-chat__title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 2px;
}

.agent-chat__status {
  font-size: 0.78rem;
  opacity: 0.9;
}

.agent-chat__close {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  color: var(--white);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

.agent-chat__body {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
  overflow: hidden;
}

.agent-chat__intro {
  padding: 18px;
  border-bottom: 1px solid var(--gray-200);
}

.agent-chat__intro p {
  margin-bottom: 12px;
  color: var(--gray-600);
  font-size: 0.92rem;
  line-height: 1.5;
}

.agent-chat__intro-form {
  display: grid;
  gap: 10px;
}

.agent-chat__field span {
  display: block;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--gray-600);
  margin-bottom: 4px;
}

.agent-chat__field input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--gray-200);
  border-radius: 10px;
  font-size: 0.95rem;
}

.agent-chat__messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px 18px;
  display: grid;
  gap: 10px;
  align-content: start;
  min-height: 0;
  background: var(--off-white);
  overscroll-behavior: contain;
}

.agent-chat__message {
  max-width: 88%;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 0.92rem;
  line-height: 1.45;
}

.agent-chat__message--user {
  justify-self: end;
  background: rgba(0, 200, 83, 0.14);
  border: 1px solid rgba(0, 200, 83, 0.22);
}

.agent-chat__message--agent {
  justify-self: start;
  background: var(--white);
  border: 1px solid var(--gray-200);
}

.agent-chat__message time {
  display: block;
  margin-top: 6px;
  font-size: 0.68rem;
  color: var(--gray-600);
}

.agent-chat__typing {
  justify-self: start;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--white);
  border: 1px solid var(--gray-200);
  font-size: 0.86rem;
  color: var(--gray-600);
}

.agent-chat__composer {
  padding: 14px 18px 18px;
  border-top: 1px solid var(--gray-200);
  background: var(--white);
}

.agent-chat__composer textarea {
  width: 100%;
  min-height: 72px;
  padding: 12px 14px;
  border: 1px solid var(--gray-200);
  border-radius: 12px;
  resize: vertical;
  font-size: 0.95rem;
  font-family: inherit;
}

.agent-chat__composer textarea:focus {
  outline: 2px solid rgba(0, 200, 83, 0.3);
  border-color: var(--green);
}

.agent-chat__actions {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

.agent-chat__actions .btn {
  flex: 1;
}

.agent-chat__error {
  margin-top: 8px;
  font-size: 0.84rem;
  color: #b42318;
  font-weight: 600;
}

.agent-chat__error[hidden],
.agent-chat__intro[hidden],
.agent-chat__composer[hidden] {
  display: none;
}

@media (max-width: 768px) {
  .agent-chat-fab {
    display: none;
  }

  .agent-chat {
    right: max(12px, env(safe-area-inset-right));
    left: max(12px, env(safe-area-inset-left));
    bottom: calc(var(--mobile-cta-height, 60px) + max(12px, env(safe-area-inset-bottom)));
    width: auto;
    max-height: min(72vh, calc(100dvh - var(--header-height) - var(--mobile-cta-height, 60px) - 24px));
  }

  body.has-mobile-hero-dock .agent-chat {
    bottom: max(12px, env(safe-area-inset-bottom));
    max-height: min(72vh, calc(100dvh - var(--header-height) - 24px));
  }

  .agent-chat.is-open {
    height: min(72vh, calc(100dvh - var(--header-height) - var(--mobile-cta-height, 60px) - 24px));
  }

  body.has-mobile-hero-dock .agent-chat.is-open {
    height: min(72vh, calc(100dvh - var(--header-height) - 24px));
  }
}

@media (max-width: 480px) {
  .agent-chat {
    max-height: min(68vh, calc(100dvh - var(--header-height) - var(--mobile-cta-height, 60px) - 16px));
  }

  .agent-chat.is-open {
    height: min(68vh, calc(100dvh - var(--header-height) - var(--mobile-cta-height, 60px) - 16px));
  }
}