/* First-party project advisor. Never auto-opens and remains usable on mobile. */
.chatbot {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 92;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-family: "Space Grotesk", sans-serif;
}

body[data-cookie="open"] .chatbot {
  bottom: calc(max(16px, env(safe-area-inset-bottom)) + 104px);
}

.chatbot [hidden] {
  display: none !important;
}

.chatbot button,
.chatbot textarea {
  font: inherit;
  letter-spacing: 0;
}

.chatbot__launcher {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid var(--fg-0);
  border-radius: 8px;
  background: var(--fg-0);
  color: var(--bg-0);
  box-shadow: 0 18px 46px rgba(0, 0, 0, 0.38);
  cursor: pointer;
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  font-weight: 600;
  transition: transform 180ms ease, box-shadow 180ms ease;
}

.chatbot__launcher:hover {
  transform: translateY(-2px);
  box-shadow: 0 22px 54px rgba(0, 0, 0, 0.48);
}

.chatbot__launcher:focus-visible,
.chatbot__head__close:focus-visible,
.chatbot__quick button:focus-visible,
.chatbot__handoff button:focus-visible,
.chatbot__banner button:focus-visible,
.chatbot__send:focus-visible,
.chatbot__sources a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.chatbot__launcher svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.chatbot__launcher__pulse {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 50%, transparent);
  animation: chatbot-pulse 1.8s ease-out infinite;
}

@keyframes chatbot-pulse {
  70% {
    box-shadow: 0 0 0 8px transparent;
  }
  100% {
    box-shadow: 0 0 0 0 transparent;
  }
}

.chatbot[data-state="open"] .chatbot__launcher {
  display: none;
}

.chatbot__panel {
  width: min(400px, calc(100vw - 32px));
  height: min(620px, calc(100vh - 32px));
  display: none;
  min-height: 420px;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--bg-1);
  color: var(--fg-0);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.58);
}

@supports (height: 100dvh) {
  .chatbot__panel {
    height: min(620px, calc(100dvh - 32px));
  }
}

.chatbot[data-state="open"] .chatbot__panel {
  display: flex;
}

.chatbot__head {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 68px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-1);
}

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

.chatbot__head__avatar {
  width: 36px;
  height: 36px;
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--bg-2);
  color: var(--accent);
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  font-weight: 700;
}

.chatbot__head__title {
  overflow: hidden;
  color: var(--fg-0);
  font-size: 15px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chatbot__head__sub {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  color: var(--fg-2);
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
}

.chatbot__head__sub::before {
  content: "";
  width: 6px;
  height: 6px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #55b685;
}

.chatbot__head__close {
  width: 44px;
  height: 44px;
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--fg-1);
  cursor: pointer;
}

.chatbot__head__close:hover {
  border-color: var(--line);
  background: var(--bg-2);
  color: var(--fg-0);
}

.chatbot__head__close svg {
  width: 18px;
  height: 18px;
}

.chatbot__body {
  min-height: 0;
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px;
  scroll-behavior: smooth;
}

.chatbot__msg,
.chatbot__typing,
.chatbot__sources {
  width: fit-content;
  max-width: 88%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-2);
  color: var(--fg-0);
}

.chatbot__msg {
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.chatbot__msg--user {
  align-self: flex-end;
  border-color: var(--fg-0);
  background: var(--fg-0);
  color: var(--bg-0);
}

.chatbot__typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 14px;
}

.chatbot__typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--fg-2);
  animation: chatbot-typing 1.1s ease-in-out infinite;
}

.chatbot__typing span:nth-child(2) {
  animation-delay: 120ms;
}

.chatbot__typing span:nth-child(3) {
  animation-delay: 240ms;
}

@keyframes chatbot-typing {
  0%,
  60%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

.chatbot__sources {
  padding: 10px 12px;
  font-size: 12px;
}

.chatbot__sources strong {
  display: block;
  margin-bottom: 6px;
  color: var(--fg-2);
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  font-weight: 500;
}

.chatbot__sources ul {
  display: grid;
  gap: 5px;
  margin: 0;
  padding-left: 16px;
}

.chatbot__sources a {
  color: var(--fg-0);
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-underline-offset: 3px;
}

.chatbot__quick {
  display: grid;
  flex: 0 0 auto;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 0 14px 10px;
}

.chatbot__quick button {
  min-width: 0;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: transparent;
  color: var(--fg-1);
  cursor: pointer;
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.chatbot__quick button:hover {
  border-color: var(--fg-2);
  background: var(--bg-2);
  color: var(--fg-0);
}

.chatbot__handoff {
  display: grid;
  flex: 0 0 auto;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  background: var(--bg-2);
}

.chatbot__handoff strong {
  grid-column: 1 / -1;
  color: var(--fg-1);
  font-size: 13px;
}

.chatbot__handoff .btn {
  width: 100%;
  min-height: 44px;
  justify-content: center;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 11px;
}

.chatbot__banner {
  display: flex;
  flex: 0 0 auto;
  align-items: flex-start;
  gap: 10px;
  margin: 0 14px 8px;
  padding: 10px 12px;
  border: 1px solid rgba(248, 113, 113, 0.45);
  border-radius: 6px;
  background: rgba(248, 113, 113, 0.08);
  color: #fecaca;
  font-size: 12px;
  line-height: 1.45;
}

.chatbot__banner button {
  min-height: 32px;
  margin-left: auto;
  padding: 4px 6px;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-family: "JetBrains Mono", monospace;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.chatbot__disclosure {
  flex: 0 0 auto;
  margin: 0;
  padding: 0 14px 8px;
  color: var(--fg-3);
  font-size: 11px;
  line-height: 1.4;
}

.chatbot__composer {
  display: flex;
  flex: 0 0 auto;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--bg-1);
}

.chatbot__composer textarea {
  min-width: 0;
  min-height: 44px;
  max-height: 140px;
  flex: 1 1 auto;
  resize: none;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--bg-0);
  color: var(--fg-0);
  font-size: 16px;
  line-height: 1.4;
}

.chatbot__composer textarea::placeholder {
  color: var(--fg-3);
}

.chatbot__composer textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.chatbot__send {
  width: 44px;
  height: 44px;
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--fg-0);
  border-radius: 6px;
  background: var(--fg-0);
  color: var(--bg-0);
  cursor: pointer;
}

.chatbot__send:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

.chatbot__send svg {
  width: 18px;
  height: 18px;
}

.chatbot .sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 640px) {
  body[data-chatbot-open="true"] {
    overflow: hidden;
  }

  .chatbot {
    right: max(8px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
  }

  body[data-cookie="open"] .chatbot {
    bottom: calc(max(8px, env(safe-area-inset-bottom)) + 136px);
  }

  .chatbot__launcher {
    width: 48px;
    height: 48px;
    min-height: 48px;
    justify-content: center;
    padding: 0;
  }

  .chatbot__launcher > span:not(.chatbot__launcher__pulse) {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .chatbot__launcher__pulse {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 7px;
    height: 7px;
  }

  .chatbot__panel {
    width: calc(100vw - 16px);
    min-height: 0;
    height: calc(100vh - 80px);
    max-height: 720px;
  }

  @supports (height: 100svh) {
    .chatbot__panel {
      height: calc(100svh - 80px);
    }
  }

  .chatbot__head {
    min-height: 64px;
    padding: 10px 12px;
  }

  .chatbot__head__close,
  .chatbot__quick button,
  .chatbot__handoff .btn,
  .chatbot__send {
    min-height: 48px;
  }

  .chatbot__head__close,
  .chatbot__send {
    width: 48px;
    height: 48px;
  }

  .chatbot__body {
    padding: 14px 12px;
  }

  .chatbot__msg {
    max-width: 92%;
  }

  .chatbot__quick {
    padding: 0 12px 8px;
  }

  .chatbot__handoff {
    padding: 8px 12px;
  }

  .chatbot__disclosure {
    padding: 0 12px 8px;
  }
}

@media (max-width: 360px) {
  .chatbot__quick,
  .chatbot__handoff {
    grid-template-columns: 1fr;
  }

  .chatbot__handoff strong {
    grid-column: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chatbot__launcher,
  .chatbot__body {
    scroll-behavior: auto;
    transition: none;
  }

  .chatbot__launcher__pulse,
  .chatbot__typing span {
    animation: none;
  }
}
