.chat-bubble {
  --chat-bubble-bottom-offset: 1rem;
  --chat-bubble-gap: 1rem;
}

.chat-bubble--with-banner {
  --chat-bubble-bottom-offset: 4.75rem;
}

.chat-bubble-launcher {
  position: fixed;
  right: 1rem;
  bottom: calc(var(--chat-bubble-bottom-offset, 1rem) + env(safe-area-inset-bottom, 0px));
  z-index: 70;
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  border: 0;
  border-radius: 9999px;
  padding: 0.72rem 0.92rem 0.72rem 0.82rem;
  background: linear-gradient(135deg, #1d4ed8, #6d28d9);
  color: #fff;
  box-shadow: 0 22px 45px rgba(29, 78, 216, 0.3);
  transition: transform 160ms ease, box-shadow 160ms ease;
  cursor: pointer;
}

.chat-bubble-launcher:hover,
.chat-bubble-launcher:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 28px 55px rgba(29, 78, 216, 0.34);
}

.chat-bubble-launcher__badge {
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.chat-bubble-launcher__icon {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 2.05rem;
  height: 2.05rem;
  border-radius: 9999px;
  background: rgba(255, 255, 255, 0.18);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14);
}

.chat-bubble-launcher__icon svg {
  width: 1.15rem;
  height: 1.15rem;
}

.chat-bubble-panel {
  font-family: "Inter", system-ui, sans-serif;
  position: fixed;
  right: 1rem;
  bottom: calc(var(--chat-bubble-bottom-offset, 1rem) + env(safe-area-inset-bottom, 0px));
  z-index: 70;
  display: flex;
  flex-direction: column;
  width: min(47rem, calc(100vw - 1.5rem));
  height: min(85vh, 60rem);
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.28);
  border-radius: 1.5rem;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 28px 80px rgba(15, 23, 42, 0.18);
  backdrop-filter: blur(18px);
  transform-origin: bottom right;
  opacity: 0;
  transform: translateY(1rem) scale(0.96);
  pointer-events: none;
  transition: opacity 300ms cubic-bezier(0.16, 1, 0.3, 1),
              transform 300ms cubic-bezier(0.16, 1, 0.3, 1);
}

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

.chat-bubble-panel.is-open {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.chat-bubble-panel__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.05rem 1.05rem 0.9rem;
  color: white;
  background: linear-gradient(145deg, #111827, #1d4ed8 65%, #6d28d9);
}

.chat-bubble-panel__eyebrow {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0.72;
}

.chat-bubble-panel__title {
  margin: 0.25rem 0 0;
  font-size: 1.25rem;
  line-height: 1.1;
  color: white;
}

.chat-bubble-panel__subtitle {
  margin: 0.35rem 0 0;
  font-size: 0.9rem;
  line-height: 1.4;
  color: rgba(255, 255, 255, 0.8);
}

.chat-bubble-panel__close {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.2rem;
  height: 2.2rem;
  border: 0;
  border-radius: 9999px;
  color: inherit;
  background: rgba(255, 255, 255, 0.14);
  transition: background-color 160ms ease, transform 160ms ease;
  cursor: pointer;
}

.chat-bubble-panel__close:hover,
.chat-bubble-panel__close:focus-visible {
  background: rgba(255, 255, 255, 0.22);
  transform: rotate(90deg);
}

.chat-bubble-panel__close svg {
  width: 1rem;
  height: 1rem;
}

.chat-bubble-notice {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.75rem 0.85rem;
  border-radius: 0.75rem;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(191, 219, 254, 0.8);
  font-size: 0.8rem;
  line-height: 1.5;
  color: #475569;
}

.chat-bubble-notice p {
  margin: 0;
  flex: 1;
  text-align: center;
}

.chat-bubble-notice__dismiss {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border: 0;
  border-radius: 9999px;
  background: transparent;
  color: #94a3b8;
  cursor: pointer;
  transition: color 160ms ease, background-color 160ms ease;
}

.chat-bubble-notice__dismiss:hover {
  color: #475569;
  background: rgba(0, 0, 0, 0.06);
}

.chat-bubble-tool-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  align-self: flex-start;
  padding: 0.5rem 0.8rem;
  border-radius: 9999px;
  font-size: 0.78rem;
  font-weight: 600;
  color: #64748b;
  background: #f1f5f9;
}

.chat-bubble-tool-indicator svg {
  animation: chat-bubble-gear-spin 2s linear infinite;
}

.chat-bubble-tool-indicator--done {
  opacity: 0.55;
  color: #94a3b8;
}

.chat-bubble-tool-indicator--done svg {
  animation: none;
}

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

@keyframes chat-bubble-gear-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.chat-bubble-messages {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 0.9rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1rem;
  background:
    radial-gradient(circle at top right, rgba(191, 219, 254, 0.55), transparent 34%),
    linear-gradient(180deg, rgba(248, 250, 252, 0.98), rgba(255, 255, 255, 0.98));
}

.chat-bubble-welcome {
  display: grid;
  gap: 0.75rem;
  padding: 1rem;
  border-radius: 1.25rem;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(191, 219, 254, 0.8);
  box-shadow: 0 14px 36px rgba(148, 163, 184, 0.12);
}

.chat-bubble-welcome__kicker {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #2563eb;
}

.chat-bubble-welcome__title {
  margin: 0;
  font-size: 1.15rem;
  line-height: 1.3;
}

.chat-bubble-welcome__body {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.55;
  color: #475569;
}

.chat-bubble-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.chat-bubble-suggestion {
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 9999px;
  padding: 0.65rem 0.85rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: #1e3a8a;
  background: white;
  transition: border-color 160ms ease, transform 160ms ease, box-shadow 160ms ease;
  cursor: pointer;
}

.chat-bubble-suggestion:hover,
.chat-bubble-suggestion:focus-visible {
  border-color: rgba(37, 99, 235, 0.55);
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(148, 163, 184, 0.16);
}

.chat-bubble-message {
  display: flex;
}

.chat-bubble-message--user {
  justify-content: flex-end;
}

.chat-bubble-message--assistant,
.chat-bubble-message--system {
  justify-content: flex-start;
}

.chat-bubble-message__bubble {
  max-width: 88%;
  border-radius: 1.15rem;
  padding: 0.85rem 0.95rem;
  font-size: 0.93rem;
  line-height: 1.55;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.08);
}

.chat-bubble-message--user .chat-bubble-message__bubble {
  color: white;
  border-bottom-right-radius: 0.4rem;
  background: linear-gradient(135deg, #1d4ed8, #6d28d9);
}

.chat-bubble-message--assistant .chat-bubble-message__bubble {
  color: #0f172a;
  border-bottom-left-radius: 0.4rem;
  background: linear-gradient(135deg, rgba(219, 234, 254, 0.55), rgba(237, 233, 254, 0.45));
  border: 1px solid rgba(191, 219, 254, 0.6);
}

.chat-bubble-message--system .chat-bubble-message__bubble {
  color: #475569;
  border-bottom-left-radius: 0.4rem;
  background: rgba(248, 250, 252, 0.92);
  border: 1px solid rgba(226, 232, 240, 0.7);
  font-size: 0.84rem;
  font-style: italic;
}

.chat-bubble-message__bubble > :first-child {
  margin-top: 0;
}

.chat-bubble-message__bubble > :last-child {
  margin-bottom: 0;
}

.chat-bubble-message__bubble p {
  margin: 0 0 0.75rem;
}

.chat-bubble-message__bubble ul,
.chat-bubble-message__bubble ol {
  margin: 0.75rem 0 0.75rem 1.2rem;
}

.chat-bubble-message__bubble li + li {
  margin-top: 0.3rem;
}

.chat-bubble-message__bubble a {
  color: #1d4ed8;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.chat-bubble-message--user .chat-bubble-message__bubble a {
  color: rgba(255, 255, 255, 0.95);
}

.chat-bubble-message__bubble code {
  border-radius: 0.45rem;
  padding: 0.1rem 0.35rem;
  background: rgba(15, 23, 42, 0.07);
  font-size: 0.82rem;
}

.chat-bubble-message__bubble pre {
  overflow-x: auto;
  border-radius: 0.95rem;
  padding: 0.9rem;
  background: #0f172a;
  color: #e2e8f0;
}

.chat-bubble-message__bubble table {
  width: 100%;
  margin: 0.85rem 0;
  display: table;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 0.88rem;
  background: #fff;
}

.chat-bubble-message__bubble thead {
  background: #f1f5f9;
}

.chat-bubble-message__bubble th,
.chat-bubble-message__bubble td {
  padding: 0.55rem 0.7rem;
  border: 1px solid #e2e8f0;
  text-align: left;
  vertical-align: top;
  white-space: normal;
  word-break: break-word;
}

.chat-bubble-message__bubble th {
  background: #f1f5f9;
  font-weight: 700;
}

.chat-bubble-message__bubble tr:nth-child(even) {
  background: #f8fafc;
}

.chat-bubble-status {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  align-self: flex-start;
  border-radius: 1.15rem;
  border-bottom-left-radius: 0.4rem;
  padding: 0.75rem 1rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: #4b5563;
  background: linear-gradient(135deg, rgba(219, 234, 254, 0.55), rgba(237, 233, 254, 0.45));
  border: 1px solid rgba(191, 219, 254, 0.6);
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.08);
}

.chat-bubble-status__dots {
  display: inline-flex;
  align-items: center;
  gap: 0.22rem;
}

.chat-bubble-status__dot {
  width: 0.38rem;
  height: 0.38rem;
  border-radius: 9999px;
  background: linear-gradient(135deg, #1d4ed8, #6d28d9);
  opacity: 0.4;
  animation: chat-bubble-dot-bounce 1.4s ease-in-out infinite;
}

.chat-bubble-status__dot:nth-child(2) {
  animation-delay: 0.16s;
}

.chat-bubble-status__dot:nth-child(3) {
  animation-delay: 0.32s;
}

.chat-bubble-fallback {
  margin: 0 1rem 1rem;
  padding: 0.9rem 1rem;
  border-radius: 1rem;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(191, 219, 254, 0.85);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.06);
}

.chat-bubble-fallback__title,
.chat-bubble-fallback__body {
  margin: 0;
}

.chat-bubble-fallback__title {
  font-size: 0.9rem;
  font-weight: 700;
  color: #0f172a;
}

.chat-bubble-fallback__body {
  margin-top: 0.35rem;
  font-size: 0.84rem;
  line-height: 1.45;
  color: #475569;
}

.chat-bubble-fallback__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.chat-bubble-fallback__link {
  font-size: 0.84rem;
  font-weight: 700;
  color: #1d4ed8;
}

.chat-bubble-fallback__cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.25rem;
  border-radius: 9999px;
  padding: 0 0.95rem;
  font-size: 0.82rem;
  font-weight: 700;
  color: white;
  background: linear-gradient(135deg, #1d4ed8, #6d28d9);
}

.chat-bubble-form {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  padding: 0.95rem 1rem calc(0.95rem + env(safe-area-inset-bottom, 0px));
  background: rgba(255, 255, 255, 0.98);
  border-top: 1px solid rgba(226, 232, 240, 0.9);
}

.chat-bubble-form__input {
  font: inherit;
  width: 100%;
  min-height: 2.85rem;
  max-height: 9rem;
  resize: none;
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 1rem;
  padding: 0.8rem 0.9rem;
  font-size: 0.92rem;
  line-height: 1.45;
  color: #0f172a;
  background: white;
}

.chat-bubble-form__input:focus {
  outline: none;
  border-color: rgba(37, 99, 235, 0.55);
  box-shadow: 0 0 0 4px rgba(191, 219, 254, 0.4);
}

.chat-bubble-form__input:disabled {
  background: rgba(248, 250, 252, 0.92);
  color: #64748b;
  cursor: wait;
}

.chat-bubble-form__send {
  flex-shrink: 0;
  min-height: 2.85rem;
  border: 0;
  border-radius: 9999px;
  padding: 0 1rem;
  font-size: 0.85rem;
  font-weight: 700;
  color: white;
  background: linear-gradient(135deg, #1d4ed8, #6d28d9);
  transition: transform 160ms ease, box-shadow 160ms ease, opacity 160ms ease;
  cursor: pointer;
}

.chat-bubble-form__send:hover,
.chat-bubble-form__send:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 12px 26px rgba(29, 78, 216, 0.26);
}

.chat-bubble-form__send:disabled {
  opacity: 0.55;
  transform: none;
  box-shadow: none;
  cursor: wait;
}

@keyframes chat-bubble-dot-bounce {
  0%, 60%, 100% {
    opacity: 0.4;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-0.25rem);
  }
}

@media (max-width: 640px) {
  .chat-bubble {
    --chat-bubble-gap: 0.75rem;
  }

  .chat-bubble--with-banner {
    --chat-bubble-bottom-offset: 4rem;
  }

  .chat-bubble-launcher {
    right: 0.75rem;
    left: auto;
    bottom: calc(var(--chat-bubble-bottom-offset, 1rem) + env(safe-area-inset-bottom, 0px));
    padding-right: 0.9rem;
  }

  .chat-bubble-panel {
    position: fixed;
    inset: 0;
    width: 100%;
    max-width: 100%;
    max-height: 100%;
    height: 100%;
    border-radius: 0;
    border: 0;
    bottom: 0;
    right: 0;
    transform-origin: bottom center;
  }

  .chat-bubble-message__bubble {
    max-width: 92%;
  }
}
