.bcw-root,
.bcw-root *,
.bcw-root *::before,
.bcw-root *::after {
  box-sizing: border-box;
}

.bcw-root {
  --bcw-accent: #2563eb;
  --bcw-accent-hover: #1d4ed8;
  --bcw-surface: #ffffff;
  --bcw-surface-alt: #f4f7fb;
  --bcw-text: #152033;
  --bcw-muted: #64748b;
  --bcw-border: #dfe6ef;
  --bcw-user-text: #ffffff;
  --bcw-assistant: #eef3f9;
  --bcw-danger: #c2413b;
  --bcw-shadow: 0 24px 70px rgba(15, 23, 42, 0.22);
  --bcw-font: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  position: fixed;
  z-index: 2147483000;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  color: var(--bcw-text);
  font-family: var(--bcw-font);
  font-size: 15px;
  line-height: 1.45;
  text-align: left;
  text-rendering: optimizeLegibility;
}

.bcw-root[data-position="left"] {
  right: auto;
  left: max(20px, env(safe-area-inset-left));
}

.bcw-root[data-theme="dark"] {
  --bcw-surface: #111827;
  --bcw-surface-alt: #172033;
  --bcw-text: #f1f5f9;
  --bcw-muted: #9aa8bc;
  --bcw-border: #2a374a;
  --bcw-assistant: #202b3c;
  --bcw-shadow: 0 24px 70px rgba(0, 0, 0, 0.5);
}

@media (prefers-color-scheme: dark) {
  .bcw-root[data-theme="auto"] {
    --bcw-surface: #111827;
    --bcw-surface-alt: #172033;
    --bcw-text: #f1f5f9;
    --bcw-muted: #9aa8bc;
    --bcw-border: #2a374a;
    --bcw-assistant: #202b3c;
    --bcw-shadow: 0 24px 70px rgba(0, 0, 0, 0.5);
  }
}

.bcw-root button,
.bcw-root textarea {
  font: inherit;
}

.bcw-launcher {
  display: grid;
  width: 60px;
  height: 60px;
  margin-left: auto;
  padding: 0;
  place-items: center;
  color: #fff;
  background: linear-gradient(145deg, #3478f6, var(--bcw-accent));
  border: 0;
  border-radius: 50%;
  box-shadow: 0 12px 28px rgba(37, 99, 235, 0.38);
  cursor: pointer;
  transition:
    transform 180ms ease,
    box-shadow 180ms ease,
    opacity 180ms ease;
}

.bcw-root[data-position="left"] .bcw-launcher {
  margin-right: auto;
  margin-left: 0;
}

.bcw-launcher:hover {
  box-shadow: 0 16px 34px rgba(37, 99, 235, 0.48);
  transform: translateY(-2px);
}

.bcw-launcher:focus-visible,
.bcw-root button:focus-visible,
.bcw-input:focus-visible,
.bcw-markdown a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--bcw-accent) 45%, transparent);
  outline-offset: 3px;
}

.bcw-root--open .bcw-launcher {
  pointer-events: none;
  opacity: 0;
  transform: scale(0.88);
}

.bcw-panel {
  position: absolute;
  right: 0;
  bottom: 0;
  display: flex;
  width: min(390px, calc(100vw - 32px));
  height: min(640px, calc(100vh - 40px));
  min-height: 420px;
  overflow: hidden;
  flex-direction: column;
  color: var(--bcw-text);
  background: var(--bcw-surface);
  border: 1px solid var(--bcw-border);
  border-radius: 22px;
  box-shadow: var(--bcw-shadow);
  opacity: 0;
  transform: translateY(18px) scale(0.97);
  transform-origin: bottom right;
  transition:
    opacity 200ms ease,
    transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.bcw-panel[hidden] {
  display: none !important;
}

.bcw-root[data-position="left"] .bcw-panel {
  right: auto;
  left: 0;
  transform-origin: bottom left;
}

.bcw-root--open .bcw-panel {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.bcw-header {
  display: flex;
  min-height: 74px;
  padding: 13px 14px 13px 16px;
  align-items: center;
  justify-content: space-between;
  color: #fff;
  background: linear-gradient(135deg, #1e55c9, #2563eb 55%, #397cf5);
}

.bcw-identity {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 11px;
}

.bcw-avatar {
  display: grid;
  width: 44px;
  height: 44px;
  overflow: hidden;
  flex: 0 0 44px;
  place-items: center;
  color: #1649b2;
  background: #fff;
  border: 2px solid rgba(255, 255, 255, 0.65);
  border-radius: 14px;
  font-size: 20px;
  font-weight: 750;
}

.bcw-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.bcw-header h2 {
  overflow: hidden;
  max-width: 245px;
  margin: 0;
  color: inherit;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bcw-status {
  display: flex;
  margin-top: 3px;
  align-items: center;
  gap: 6px;
  color: rgba(255, 255, 255, 0.84);
  font-size: 12px;
}

.bcw-status__dot {
  width: 7px;
  height: 7px;
  background: #7ef0a8;
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(126, 240, 168, 0.15);
}

.bcw-status--error .bcw-status__dot {
  background: #ffd07a;
  box-shadow: 0 0 0 3px rgba(255, 208, 122, 0.15);
}

.bcw-close {
  display: grid;
  width: 40px;
  height: 40px;
  padding: 0;
  place-items: center;
  color: #fff;
  background: transparent;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
}

.bcw-close:hover {
  background: rgba(255, 255, 255, 0.14);
}

.bcw-messages {
  flex: 1;
  padding: 18px 15px 14px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  background:
    radial-gradient(circle at top right, rgba(37, 99, 235, 0.05), transparent 35%),
    var(--bcw-surface-alt);
  scrollbar-color: var(--bcw-border) transparent;
  scrollbar-width: thin;
}

.bcw-message {
  display: flex;
  margin: 0 0 13px;
  animation: bcw-message-in 180ms ease both;
}

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

.bcw-bubble {
  position: relative;
  max-width: 84%;
  padding: 10px 13px;
  color: var(--bcw-text);
  background: var(--bcw-assistant);
  border: 1px solid color-mix(in srgb, var(--bcw-border) 75%, transparent);
  border-radius: 7px 17px 17px 17px;
  overflow-wrap: anywhere;
}

.bcw-message--user .bcw-bubble {
  color: var(--bcw-user-text);
  background: var(--bcw-accent);
  border-color: transparent;
  border-radius: 17px 17px 7px 17px;
  white-space: pre-wrap;
}

.bcw-message--error .bcw-bubble {
  border-color: color-mix(in srgb, var(--bcw-danger) 40%, var(--bcw-border));
}

.bcw-markdown > :first-child {
  margin-top: 0;
}

.bcw-markdown > :last-child {
  margin-bottom: 0;
}

.bcw-markdown p {
  margin: 0 0 9px;
}

.bcw-markdown h3,
.bcw-markdown h4,
.bcw-markdown h5,
.bcw-markdown h6 {
  margin: 12px 0 6px;
  color: var(--bcw-text);
  font-size: 1em;
  font-weight: 750;
}

.bcw-markdown ul,
.bcw-markdown ol {
  margin: 7px 0 9px;
  padding-left: 22px;
}

.bcw-markdown li + li {
  margin-top: 4px;
}

.bcw-markdown a {
  color: var(--bcw-accent);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.bcw-markdown code {
  padding: 2px 5px;
  background: color-mix(in srgb, var(--bcw-text) 9%, transparent);
  border-radius: 5px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.88em;
}

.bcw-markdown pre {
  max-width: 100%;
  margin: 9px 0;
  padding: 11px 12px;
  overflow-x: auto;
  color: #e5edf8;
  background: #101827;
  border-radius: 10px;
}

.bcw-markdown pre code {
  padding: 0;
  color: inherit;
  background: transparent;
  white-space: pre;
}

.bcw-markdown blockquote {
  margin: 8px 0;
  padding-left: 10px;
  color: var(--bcw-muted);
  border-left: 3px solid var(--bcw-accent);
}

.bcw-table-wrap {
  max-width: 100%;
  margin: 9px 0;
  overflow-x: auto;
}

.bcw-markdown table {
  width: 100%;
  min-width: 240px;
  border-spacing: 0;
  border-collapse: collapse;
  font-size: 13px;
}

.bcw-markdown th,
.bcw-markdown td {
  padding: 7px 8px;
  text-align: left;
  border: 1px solid var(--bcw-border);
}

.bcw-markdown th {
  background: color-mix(in srgb, var(--bcw-accent) 8%, var(--bcw-surface));
  font-weight: 700;
}

.bcw-copy {
  position: absolute;
  right: -7px;
  bottom: -9px;
  display: grid;
  width: 27px;
  height: 27px;
  padding: 0;
  place-items: center;
  color: var(--bcw-muted);
  background: var(--bcw-surface);
  border: 1px solid var(--bcw-border);
  border-radius: 9px;
  box-shadow: 0 3px 10px rgba(15, 23, 42, 0.08);
  cursor: pointer;
  opacity: 0;
  transition: opacity 160ms ease;
}

.bcw-message--assistant:hover .bcw-copy,
.bcw-copy:focus-visible,
.bcw-copy--done {
  opacity: 1;
}

.bcw-copy--done .bcw-icon--copy {
  background-image: url("./assets/icons/check.svg");
}

.bcw-quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 13px;
}

.bcw-quick-action {
  padding: 8px 14px;
  color: var(--bcw-accent);
  background: var(--bcw-surface);
  border: 1px solid var(--bcw-border);
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  text-align: left;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    transform 160ms ease;
}

.bcw-quick-action:hover {
  border-color: var(--bcw-accent);
  background: color-mix(in srgb, var(--bcw-accent) 8%, var(--bcw-surface));
}

.bcw-quick-action:focus-visible {
  outline: 2px solid var(--bcw-accent);
  outline-offset: 2px;
}

.bcw-quick-action:active {
  transform: translateY(1px);
}

.bcw-retry {
  display: block;
  margin-top: 9px;
  padding: 5px 10px;
  color: var(--bcw-accent);
  background: var(--bcw-surface);
  border: 1px solid var(--bcw-border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

.bcw-typing-row {
  margin-bottom: 10px;
}

.bcw-typing {
  display: flex;
  width: 58px;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.bcw-typing span {
  width: 6px;
  height: 6px;
  background: var(--bcw-muted);
  border-radius: 50%;
  animation: bcw-typing 1.2s infinite ease-in-out;
}

.bcw-typing span:nth-child(2) {
  animation-delay: 140ms;
}

.bcw-typing span:nth-child(3) {
  animation-delay: 280ms;
}

.bcw-composer {
  display: flex;
  min-height: 76px;
  padding: 12px;
  align-items: flex-end;
  gap: 9px;
  background: var(--bcw-surface);
  border-top: 1px solid var(--bcw-border);
}

.bcw-input-wrap {
  position: relative;
  display: flex;
  min-width: 0;
  flex: 1;
  align-items: flex-end;
  background: var(--bcw-surface-alt);
  border: 1px solid var(--bcw-border);
  border-radius: 14px;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease;
}

.bcw-input-wrap:focus-within {
  border-color: var(--bcw-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--bcw-accent) 12%, transparent);
}

.bcw-input {
  width: 100%;
  min-height: 46px;
  max-height: 120px;
  margin: 0;
  padding: 12px 48px 10px 12px;
  resize: none;
  overflow-y: auto;
  color: var(--bcw-text);
  caret-color: var(--bcw-accent);
  background: transparent;
  border: 0;
  border-radius: inherit;
  outline: none;
  line-height: 1.45;
}

.bcw-input::placeholder {
  color: var(--bcw-muted);
}

.bcw-input:disabled {
  cursor: wait;
  opacity: 0.65;
}

.bcw-counter {
  position: absolute;
  right: 9px;
  bottom: 6px;
  color: var(--bcw-muted);
  font-size: 10px;
  pointer-events: none;
}

.bcw-send {
  display: grid;
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  padding: 0;
  place-items: center;
  color: #fff;
  background: var(--bcw-accent);
  border: 0;
  border-radius: 14px;
  cursor: pointer;
  transition:
    background 160ms ease,
    transform 160ms ease,
    opacity 160ms ease;
}

.bcw-send:hover:not(:disabled) {
  background: var(--bcw-accent-hover);
  transform: translateY(-1px);
}

.bcw-send:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.bcw-icon {
  display: block;
  width: 20px;
  height: 20px;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
}

.bcw-icon--chat {
  width: 27px;
  height: 27px;
  background-image: url("./assets/icons/chat.svg");
}

.bcw-icon--close {
  background-image: url("./assets/icons/close.svg");
}

.bcw-icon--send {
  width: 21px;
  height: 21px;
  background-image: url("./assets/icons/send.svg");
}

.bcw-icon--copy {
  width: 14px;
  height: 14px;
  background-image: url("./assets/icons/copy.svg");
}

.bcw-copy-helper {
  position: fixed;
  left: -9999px;
  opacity: 0;
}

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

@keyframes bcw-message-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

@keyframes bcw-typing {
  0%,
  60%,
  100% {
    opacity: 0.45;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-4px);
  }
}

@media (max-width: 540px) {
  .bcw-root,
  .bcw-root[data-position="left"] {
    right: max(12px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
    left: max(12px, env(safe-area-inset-left));
  }

  .bcw-launcher,
  .bcw-root[data-position="left"] .bcw-launcher {
    margin-right: 0;
    margin-left: auto;
  }

  .bcw-root[data-position="left"] .bcw-launcher {
    margin-right: auto;
    margin-left: 0;
  }

  .bcw-panel,
  .bcw-root[data-position="left"] .bcw-panel {
    position: fixed;
    top: max(10px, env(safe-area-inset-top));
    right: max(10px, env(safe-area-inset-right));
    bottom: max(10px, env(safe-area-inset-bottom));
    left: max(10px, env(safe-area-inset-left));
    width: auto;
    height: auto;
    min-height: 0;
    border-radius: 20px;
    transform-origin: bottom center;
  }

  .bcw-header {
    min-height: 70px;
  }

  .bcw-messages {
    padding-right: 12px;
    padding-left: 12px;
  }

  .bcw-bubble {
    max-width: 88%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .bcw-root *,
  .bcw-root *::before,
  .bcw-root *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
