/* BuyCoded chatbox widget — scoped under #bc-chatbox / .bc-* only. */

#bc-chatbox {
  /* Aliased token names preserved; remapped to LOCKED dark palette. */
  --bc-orange: #4f8eff;
  --bc-orange-dark: #6ba0ff;
  --bc-orange-soft: rgba(79,142,255,.14);
  --bc-orange-tint: rgba(79,142,255,.22);
  --bc-ink: #e8edf7;
  --bc-muted: #aab3c5;
  --bc-bg: #0f1629;
  --bc-surface-2: #141d33;
  --bc-line: #232e4a;
  --bc-user-bg: #1b2643;
  --bc-shadow: 0 20px 50px rgba(0, 0, 0, .55);
  --bc-radius: 16px;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--bc-ink);
  line-height: 1.45;
  font-size: 15px;
}

#bc-chatbox *,
#bc-chatbox *::before,
#bc-chatbox *::after {
  box-sizing: border-box;
}

/* --- Floating bubble --- */
.bc-chatbox-bubble {
  position: fixed;
  bottom: 16px;
  right: 16px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--bc-orange);
  color: #fff;
  border: 0;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(79, 142, 255, .35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2147483000;
  transition: transform .15s ease, background .15s ease, box-shadow .15s ease;
}

.bc-chatbox-bubble:hover {
  background: var(--bc-orange-dark);
  transform: translateY(-1px);
}

.bc-chatbox-bubble:focus-visible {
  outline: 3px solid rgba(79, 142, 255, .45);
  outline-offset: 2px;
}

.bc-chatbox-bubble-icon {
  display: block;
  pointer-events: none;
}

.bc-chatbox-bubble-badge {
  position: absolute;
  top: 4px;
  right: 6px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  background: var(--bc-bg);
  color: var(--bc-orange);
  font-size: 10px;
  font-weight: 700;
  border-radius: 999px;
  line-height: 16px;
  text-align: center;
  pointer-events: none;
}

/* Initial attention pulse — auto-cancels after 5s via JS / animation. */
.bc-chatbox-pulse::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--bc-orange);
  opacity: .6;
  animation: bc-chatbox-pulse 1.6s ease-out 3;
  pointer-events: none;
}

@keyframes bc-chatbox-pulse {
  0%   { transform: scale(1);   opacity: .6; }
  100% { transform: scale(1.6); opacity: 0;  }
}

#bc-chatbox.bc-open .bc-chatbox-bubble {
  /* Hide the bubble while panel is open on small screens. */
}

#bc-chatbox.bc-open .bc-chatbox-bubble-badge {
  display: none;
}

/* --- Panel --- */
.bc-chatbox-panel {
  position: fixed;
  bottom: 84px;
  right: 16px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 100px);
  background: var(--bc-bg);
  border-radius: var(--bc-radius);
  box-shadow: var(--bc-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 2147483001;
  transform: translateY(12px) scale(.98);
  opacity: 0;
  pointer-events: none;
  transition: transform .18s ease, opacity .18s ease;
  border: 1px solid var(--bc-line);
}

#bc-chatbox.bc-open .bc-chatbox-panel {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: auto;
}

.bc-chatbox-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: linear-gradient(135deg, var(--bc-orange) 0%, var(--bc-orange-dark) 100%);
  color: #fff;
  flex: 0 0 auto;
}

.bc-chatbox-title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.bc-chatbox-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .18);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

.bc-chatbox-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
}

.bc-chatbox-subtitle {
  margin: 2px 0 0;
  font-size: 12px;
  color: rgba(255, 255, 255, .85);
  line-height: 1.2;
}

.bc-chatbox-close {
  background: transparent;
  color: #fff;
  border: 0;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s ease;
}

.bc-chatbox-close:hover {
  background: rgba(255, 255, 255, .15);
}

.bc-chatbox-close:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 1px;
}

/* --- Message log --- */
.bc-chatbox-log {
  list-style: none;
  margin: 0;
  padding: 16px;
  flex: 1 1 auto;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bc-bg);
  scroll-behavior: smooth;
}

.bc-msg {
  display: flex;
  max-width: 100%;
}

.bc-msg-bubble {
  max-width: 84%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 14.5px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  animation: bc-msg-in .18s ease-out;
}

@keyframes bc-msg-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0);   }
}

.bc-msg-user {
  justify-content: flex-end;
}

.bc-msg-user .bc-msg-bubble {
  background: var(--bc-user-bg);
  color: var(--bc-ink);
  border-bottom-right-radius: 4px;
}

.bc-msg-assistant {
  justify-content: flex-start;
}

.bc-msg-assistant .bc-msg-bubble {
  background: var(--bc-orange-soft);
  color: var(--bc-ink);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--bc-orange-tint);
}

.bc-msg-system .bc-msg-bubble {
  background: var(--bc-orange-soft);
  color: var(--bc-ink);
  font-size: 13.5px;
  border: 1px solid var(--bc-orange-tint);
  border-radius: 10px;
  text-align: center;
  margin: 0 auto;
}

/* --- Typing indicator --- */
.bc-chatbox-typing {
  display: flex;
  gap: 4px;
  padding: 6px 18px 10px;
  background: var(--bc-bg);
  align-items: center;
}

.bc-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--bc-orange);
  opacity: .35;
  animation: bc-typing 1.1s infinite ease-in-out;
}

.bc-typing-dot:nth-child(2) { animation-delay: .15s; }
.bc-typing-dot:nth-child(3) { animation-delay: .30s; }

@keyframes bc-typing {
  0%, 80%, 100% { transform: scale(.7); opacity: .35; }
  40%           { transform: scale(1);  opacity: 1;   }
}

/* --- Lead capture form --- */
.bc-chatbox-lead {
  border-top: 1px solid var(--bc-line);
  background: var(--bc-bg);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bc-chatbox-lead-intro {
  margin: 0;
  font-size: 13.5px;
  color: var(--bc-muted);
}

.bc-chatbox-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.bc-chatbox-field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--bc-ink);
}

.bc-chatbox-field-hint {
  color: var(--bc-muted);
  font-weight: 400;
}

.bc-chatbox-field input {
  padding: 9px 11px;
  border: 1px solid var(--bc-line);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  color: var(--bc-ink);
  background: var(--bc-bg);
  transition: border-color .15s ease, box-shadow .15s ease;
}

.bc-chatbox-field input:focus {
  outline: none;
  border-color: var(--bc-orange);
  box-shadow: 0 0 0 3px rgba(79, 142, 255, .15);
}

.bc-chatbox-lead-row {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.bc-chatbox-lead-cancel,
.bc-chatbox-lead-submit {
  padding: 9px 14px;
  border-radius: 8px;
  border: 0;
  font-size: 14px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}

.bc-chatbox-lead-cancel {
  background: var(--bc-user-bg);
  color: var(--bc-ink);
}

.bc-chatbox-lead-cancel:hover { background: var(--bc-line); }

.bc-chatbox-lead-submit {
  background: var(--bc-orange);
  color: #fff;
}

.bc-chatbox-lead-submit:hover { background: var(--bc-orange-dark); }

.bc-chatbox-lead-submit:disabled,
.bc-chatbox-lead-cancel:disabled {
  opacity: .6;
  cursor: not-allowed;
}

/* --- Input row --- */
.bc-chatbox-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px 12px;
  background: var(--bc-bg);
  border-top: 1px solid var(--bc-line);
  flex: 0 0 auto;
}

.bc-chatbox-input {
  flex: 1 1 auto;
  resize: none;
  min-height: 40px;
  max-height: 140px;
  padding: 10px 12px;
  font-size: 14.5px;
  font-family: inherit;
  color: var(--bc-ink);
  background: var(--bc-user-bg);
  border: 1px solid var(--bc-line);
  border-radius: 12px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}

.bc-chatbox-input:focus {
  border-color: var(--bc-orange);
  background: var(--bc-bg);
  box-shadow: 0 0 0 3px rgba(79, 142, 255, .15);
}

.bc-chatbox-send {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 0;
  background: var(--bc-orange);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .15s ease, transform .15s ease;
}

.bc-chatbox-send:hover { background: var(--bc-orange-dark); }

.bc-chatbox-send:disabled {
  background: var(--bc-line);
  color: var(--bc-muted);
  cursor: not-allowed;
}

.bc-chatbox-send:focus-visible {
  outline: 2px solid var(--bc-orange-dark);
  outline-offset: 2px;
}

.bc-chatbox-footer-note {
  margin: 0;
  padding: 6px 14px 10px;
  font-size: 11.5px;
  color: var(--bc-muted);
  text-align: center;
  background: var(--bc-bg);
}

.bc-chatbox-footer-note a {
  color: var(--bc-orange);
  text-decoration: none;
}

.bc-chatbox-footer-note a:hover { text-decoration: underline; }

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

/* --- Mobile (full-screen panel) --- */
@media (max-width: 480px) {
  .bc-chatbox-panel {
    bottom: 0;
    right: 0;
    left: 0;
    top: 0;
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    border: 0;
  }

  #bc-chatbox.bc-open .bc-chatbox-bubble {
    display: none;
  }
}

/* Respect reduced motion. */
@media (prefers-reduced-motion: reduce) {
  .bc-chatbox-panel,
  .bc-msg-bubble,
  .bc-chatbox-bubble,
  .bc-chatbox-pulse::after,
  .bc-typing-dot {
    transition: none !important;
    animation: none !important;
  }
}
