:root {
  --ink: #221833;
  --muted: #655b76;
  --purple: #6c3bd2;
  --purple-dark: #3c1a78;
  --teal: #13b9b2;
  --teal-dark: #067f83;
  --yellow: #ffe681;
  --yellow-soft: #fff4bc;
  --white: #fffdf8;
  --shadow: 0 24px 60px rgba(37, 20, 83, 0.18);
  --body-font: "Inter", Arial, sans-serif;
  --display-font: "Fredoka", Arial, sans-serif;
}

.bulby-chat-widget {
  position: fixed;
  right: 18px;
  bottom: 18px;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 90;
  display: grid;
  justify-items: end;
  gap: 12px;
  pointer-events: none;
  transition: transform 180ms ease;
}

.bulby-chat-widget,
.bulby-chat-widget * {
  box-sizing: border-box;
}

.bulby-chat-widget > * {
  pointer-events: auto;
}

.bulby-chat-widget.is-open {
  width: min(430px, calc(100vw - 24px));
  align-items: stretch;
  justify-items: stretch;
}

.bulby-chat-widget.is-open .bulby-chat-launcher {
  display: none;
}

.bulby-chat-widget.is-open .bulby-chat-panel {
  width: 100%;
}

.bulby-chat-launcher {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  max-width: min(280px, calc(100vw - 32px));
  padding: 7px 17px 7px 7px;
  border: 1px solid rgba(108, 59, 210, 0.2);
  border-radius: 999px;
  color: var(--purple-dark);
  background: rgba(255, 253, 248, 0.96);
  box-shadow: 0 18px 42px rgba(37, 20, 83, 0.22);
  font: inherit;
  font-weight: 900;
  letter-spacing: 0;
  cursor: pointer;
  transition:
    border-color 180ms ease,
    box-shadow 180ms ease,
    transform 180ms ease;
}

.bulby-chat-launcher:hover,
.bulby-chat-launcher:focus-visible {
  border-color: rgba(19, 185, 178, 0.65);
  box-shadow: 0 22px 48px rgba(37, 20, 83, 0.26);
  transform: translateY(-2px);
}

.bulby-chat-launcher-avatar {
  position: relative;
  display: grid;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  place-items: center;
  flex: 0 0 auto;
  background: linear-gradient(135deg, var(--yellow), #fff4bc);
  box-shadow: inset 0 0 0 2px rgba(255, 253, 248, 0.9);
}

.bulby-chat-launcher-avatar img,
.bulby-chat-avatar {
  display: block;
  border-radius: 999px;
  object-fit: contain;
}

.bulby-chat-launcher-avatar img {
  width: 50px;
  height: 50px;
  transform: translateY(-2px);
}

.bulby-chat-online-dot {
  position: absolute;
  right: 0;
  bottom: 2px;
  width: 11px;
  height: 11px;
  border: 2px solid var(--white);
  border-radius: 999px;
  background: var(--teal);
  box-shadow: 0 0 0 2px rgba(19, 185, 178, 0.16);
}

.bulby-chat-launcher-text {
  line-height: 1.1;
  white-space: nowrap;
}

.bulby-chat-panel {
  display: flex;
  flex-direction: column;
  width: min(430px, calc(100vw - 24px));
  max-width: none;
  height: min(640px, calc(100vh - 96px));
  height: min(640px, calc(100dvh - 96px));
  max-height: calc(100vh - 96px);
  max-height: calc(100dvh - 96px);
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(108, 59, 210, 0.18);
  border-radius: 24px;
  background:
    radial-gradient(circle at 12% 14%, rgba(255, 230, 129, 0.28), transparent 9rem),
    linear-gradient(180deg, #fffdf8 0%, #f6fffe 100%);
  box-shadow: var(--shadow);
}

.bulby-chat-widget .bulby-chat-panel {
  margin: 0;
  padding: 0;
}

.bulby-chat-widget .bulby-chat-panel > * {
  width: 100%;
  max-width: none;
  margin-right: 0;
  margin-left: 0;
}

.bulby-chat-panel[hidden] {
  display: none;
}

.bulby-chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-width: 0;
  flex: 0 0 auto;
  padding: 14px;
  border-bottom: 1px solid rgba(34, 24, 51, 0.1);
  background:
    linear-gradient(135deg, rgba(108, 59, 210, 0.13), rgba(19, 185, 178, 0.12)),
    var(--white);
}

.bulby-chat-avatar {
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  background: var(--yellow-soft);
  box-shadow: 0 8px 20px rgba(108, 59, 210, 0.16);
}

.bulby-chat-identity {
  display: grid;
  gap: 2px;
  min-width: 0;
  margin-right: auto;
}

.bulby-chat-identity strong {
  color: var(--purple-dark);
  font-family: var(--display-font);
  font-size: 1.1rem;
  line-height: 1;
}

.bulby-chat-identity span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.bulby-chat-identity span::before {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--teal);
  content: "";
}

.bulby-chat-close {
  position: relative;
  display: grid;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  place-items: center;
  flex: 0 0 auto;
  color: var(--purple-dark);
  background: rgba(255, 253, 248, 0.74);
  cursor: pointer;
  transition:
    background 180ms ease,
    transform 180ms ease;
}

.bulby-chat-close:hover,
.bulby-chat-close:focus-visible {
  background: rgba(108, 59, 210, 0.12);
  transform: scale(1.04);
}

.bulby-chat-close span,
.bulby-chat-close span::before,
.bulby-chat-close span::after {
  display: block;
  width: 15px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
}

.bulby-chat-close span {
  position: relative;
  background: transparent;
}

.bulby-chat-close span::before,
.bulby-chat-close span::after {
  position: absolute;
  top: 50%;
  left: 50%;
  content: "";
  transform-origin: center;
}

.bulby-chat-close span::before {
  transform: translate(-50%, -50%) rotate(45deg);
}

.bulby-chat-close span::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}

.bulby-chat-messages {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  min-height: 0;
  padding: 16px;
  overflow-y: auto;
  overflow-x: hidden;
  background:
    linear-gradient(180deg, rgba(255, 253, 248, 0.98), rgba(246, 255, 254, 0.96));
}

.bulby-chat-message-row {
  display: flex;
  width: 100%;
  min-width: 0;
}

.bulby-chat-message-row.is-bulby {
  justify-content: flex-start;
}

.bulby-chat-message-row.is-user {
  justify-content: flex-end;
}

.bulby-chat-bubble,
.bulby-chat-typing {
  max-width: min(92%, 100%);
  min-width: 0;
  border: 1px solid rgba(34, 24, 51, 0.08);
  box-shadow: 0 8px 18px rgba(37, 20, 83, 0.08);
}

.bulby-chat-bubble {
  height: auto;
  min-height: 0;
  padding: 10px 12px;
  border-radius: 18px;
  font-size: 0.94rem;
  font-weight: 700;
  line-height: 1.4;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: normal;
  hyphens: auto;
  overflow: hidden;
}

.bulby-chat-message-row.is-bulby .bulby-chat-bubble {
  border-bottom-left-radius: 7px;
  color: var(--purple-dark);
  background: #f2ecff;
  white-space: pre-line;
}

.bulby-chat-message-row.is-user .bulby-chat-bubble {
  border-bottom-right-radius: 7px;
  color: white;
  background: linear-gradient(135deg, var(--purple), var(--purple-dark));
}

.bulby-chat-typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  width: auto;
  padding: 12px 14px;
  border-radius: 18px 18px 18px 7px;
  background: #f2ecff;
}

.bulby-chat-typing span {
  display: block;
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--purple);
  opacity: 0.35;
  animation: bulby-chat-typing 900ms ease-in-out infinite;
}

.bulby-chat-typing span:nth-child(2) {
  animation-delay: 140ms;
}

.bulby-chat-typing span:nth-child(3) {
  animation-delay: 280ms;
}

.bulby-chat-action-card {
  display: grid;
  gap: 10px;
  width: min(100%, 310px);
  min-width: 0;
  padding: 12px;
  border: 1px solid rgba(108, 59, 210, 0.14);
  border-radius: 18px 18px 18px 7px;
  color: var(--purple-dark);
  background: #f2ecff;
  box-shadow: 0 8px 18px rgba(37, 20, 83, 0.08);
}

.bulby-chat-action-card p {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 800;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.bulby-chat-action-buttons,
.bulby-chat-option-list {
  display: grid;
  gap: 8px;
}

.bulby-chat-action-buttons {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.bulby-chat-recommendations {
  display: grid;
  gap: 8px;
  width: 100%;
  flex: 0 0 auto;
  padding: 12px 16px 10px;
  border-top: 1px solid rgba(108, 59, 210, 0.1);
  background: #fffdf8;
}

.bulby-chat-recommendations[hidden],
.bulby-chat-ghost[hidden] {
  display: none;
}

.bulby-chat-assist-label {
  margin: 0;
  color: var(--teal-dark);
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0.03em;
  line-height: 1.1;
  text-transform: uppercase;
}

.bulby-chat-option,
.bulby-chat-action,
.bulby-chat-send {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: auto;
  min-height: 42px;
  border: 1px solid rgba(108, 59, 210, 0.18);
  border-radius: 18px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 850;
  line-height: 1.28;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: normal;
  hyphens: auto;
  cursor: pointer;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    color 160ms ease,
    transform 160ms ease;
}

.bulby-chat-option,
.bulby-chat-action {
  display: block;
  padding: 10px 13px;
  color: var(--purple-dark);
  background: white;
  box-shadow: 0 8px 18px rgba(37, 20, 83, 0.06);
  text-align: left;
}

.bulby-chat-action {
  text-align: center;
}

.bulby-chat-action.primary,
.bulby-chat-send {
  color: white;
  background: linear-gradient(135deg, var(--purple), var(--purple-dark));
}

.bulby-chat-option:hover,
.bulby-chat-option:focus-visible,
.bulby-chat-action:hover,
.bulby-chat-action:focus-visible {
  border-color: rgba(19, 185, 178, 0.7);
  color: #16333a;
  background: var(--yellow-soft);
  transform: translateY(-1px);
}

.bulby-chat-action.primary:hover,
.bulby-chat-action.primary:focus-visible,
.bulby-chat-send:hover,
.bulby-chat-send:focus-visible {
  color: white;
  background: linear-gradient(135deg, var(--purple-dark), #241144);
}

.bulby-chat-composer {
  display: grid;
  width: 100%;
  flex: 0 0 auto;
  padding: 10px 16px 16px;
  border-top: 1px solid rgba(108, 59, 210, 0.08);
  background: #f6fffe;
}

.bulby-chat-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: stretch;
}

.bulby-chat-input-shell {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 46px;
  overflow: hidden;
  border: 1px solid rgba(108, 59, 210, 0.22);
  border-radius: 999px;
  background: white;
  box-shadow: inset 0 1px 0 rgba(34, 24, 51, 0.03);
}

.bulby-chat-input {
  position: relative;
  z-index: 1;
  width: 100%;
  min-width: 0;
  min-height: 46px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  color: var(--ink);
  background: transparent;
  box-shadow: none;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 750;
}

.bulby-chat-ghost {
  display: flex;
  align-items: center;
  min-width: 0;
  min-height: 46px;
  padding: 0 14px;
  overflow: hidden;
  color: rgba(70, 59, 88, 0.42);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 750;
  line-height: 1;
  pointer-events: none;
  white-space: nowrap;
}

.bulby-chat-ghost,
.bulby-chat-input {
  grid-area: 1 / 1;
}

.bulby-chat-ghost-prefix {
  visibility: hidden;
}

.bulby-chat-ghost-suffix {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bulby-chat-input::placeholder {
  color: rgba(70, 59, 88, 0.65);
}

.bulby-chat-send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: auto;
  min-width: 72px;
  padding: 0 16px;
  border-color: transparent;
  border-radius: 999px;
  text-align: center;
}

.bulby-chat-close:focus-visible,
.bulby-chat-option:focus-visible,
.bulby-chat-action:focus-visible,
.bulby-chat-send:focus-visible {
  outline: 3px solid var(--purple-dark);
  outline-offset: 2px;
}

.bulby-chat-input-shell:focus-within {
  outline: 3px solid var(--purple-dark);
  outline-offset: 2px;
}

.bulby-chat-option:disabled,
.bulby-chat-action:disabled,
.bulby-chat-send:disabled {
  cursor: wait;
  opacity: 0.72;
  transform: none;
}

@keyframes bulby-chat-typing {
  0%,
  80%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }

  40% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

@media (max-width: 560px) {
  .bulby-chat-widget {
    right: 12px;
    bottom: 12px;
    bottom: max(12px, env(safe-area-inset-bottom));
    gap: 8px;
  }

  .bulby-chat-widget.is-open {
    width: calc(100vw - 24px);
  }

  .bulby-chat-widget.is-avoiding-submit {
    transform: translateY(-62px);
    transform: translateY(calc(-62px - env(safe-area-inset-bottom)));
  }

  .bulby-chat-launcher {
    min-height: 48px;
    max-width: calc(100vw - 24px);
    padding: 6px 13px 6px 6px;
    gap: 8px;
  }

  .bulby-chat-launcher {
    width: 54px;
    min-width: 54px;
    min-height: 54px;
    padding: 6px;
    gap: 0;
  }

  .bulby-chat-launcher-avatar {
    width: 38px;
    height: 38px;
  }

  .bulby-chat-launcher-avatar img {
    width: 44px;
    height: 44px;
  }

  .bulby-chat-launcher-text {
    font-size: 0.82rem;
  }

  .bulby-chat-launcher-text {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .bulby-chat-panel {
    width: calc(100vw - 24px);
    max-width: none;
    height: calc(100vh - 84px);
    height: calc(100dvh - 84px);
    max-height: calc(100vh - 84px);
    max-height: calc(100dvh - 84px);
    border-radius: 20px;
  }

  .bulby-chat-header {
    padding: 12px;
  }

  .bulby-chat-avatar {
    width: 42px;
    height: 42px;
  }

  .bulby-chat-messages {
    padding: 14px;
  }

  .bulby-chat-recommendations {
    padding: 10px 14px 8px;
  }

  .bulby-chat-composer {
    padding: 8px 14px 14px;
    padding-bottom: max(14px, env(safe-area-inset-bottom));
  }

  .bulby-chat-action-buttons {
    grid-template-columns: 1fr;
  }

  .bulby-chat-bubble,
  .bulby-chat-typing,
  .bulby-chat-action-card {
    max-width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .bulby-chat-launcher,
  .bulby-chat-widget,
  .bulby-chat-close,
  .bulby-chat-option,
  .bulby-chat-action,
  .bulby-chat-send {
    transition: none;
  }

  .bulby-chat-typing span {
    animation: none;
    opacity: 0.72;
    transform: none;
  }
}

@media print {
  .bulby-chat-widget {
    display: none !important;
  }
}
