/*
 * BM Chatbot — "Precision" brand chat widget.
 * Self-contained, no external fonts, no framework.
 * Custom properties fall back gracefully when theme tokens are absent.
 */

#bm-chat-root {
  --bm-navy: var(--ink-primary, #0B1B3A);
  --bm-navy-deep: #050D1F;
  --bm-amber: var(--amber, #F4A300);
  --bm-surface: #ffffff;
  --bm-muted: #647585;
  --bm-line: #e6e9ee;
  --bm-ink: #1a2433;

  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
    Helvetica, Arial, sans-serif;
}

#bm-chat-root *,
#bm-chat-root *::before,
#bm-chat-root *::after {
  box-sizing: border-box;
}

/* Utility */
.bm-chat-hidden {
  display: none !important;
}

.bm-chat-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;
}

/* ---- Launcher ---------------------------------------------------------- */
.bm-chat-launcher {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 2147483000;

  display: inline-flex;
  align-items: center;
  gap: 8px;

  padding: 12px 18px;
  border: 0;
  border-radius: 999px;

  background: var(--bm-navy);
  color: #ffffff;

  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  line-height: 1;

  cursor: pointer;
  box-shadow: 0 6px 20px rgba(5, 13, 31, 0.28);
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.bm-chat-launcher:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 26px rgba(5, 13, 31, 0.34);
  background: var(--bm-navy-deep);
}

.bm-chat-launcher:focus-visible {
  outline: 2px solid var(--bm-amber);
  outline-offset: 2px;
}

.bm-chat-icon {
  color: var(--bm-amber);
  flex: 0 0 auto;
}

.bm-chat-launcher-text {
  white-space: nowrap;
}

/* ---- Panel ------------------------------------------------------------- */
.bm-chat-panel {
  position: fixed;
  bottom: 88px;
  right: 20px;
  z-index: 2147483000;

  display: flex;
  flex-direction: column;

  width: 370px;
  max-width: calc(100vw - 40px);
  max-height: 70vh;

  background: var(--bm-surface);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 18px 50px rgba(5, 13, 31, 0.32);
}

/* ---- Header ------------------------------------------------------------ */
.bm-chat-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;

  padding: 16px 18px;
  background: var(--bm-navy);
  color: #ffffff;
}

.bm-chat-title {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.2;
}

.bm-chat-subtitle {
  margin-top: 2px;
  font-size: 12.5px;
  line-height: 1.3;
  color: rgba(255, 255, 255, 0.72);
}

.bm-chat-close {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;

  width: 30px;
  height: 30px;
  padding: 0;

  border: 0;
  border-radius: 8px;
  background: transparent;
  color: rgba(255, 255, 255, 0.85);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.bm-chat-close:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
}

.bm-chat-close:focus-visible {
  outline: 2px solid var(--bm-amber);
  outline-offset: 2px;
}

/* ---- Header email invite (optional, anonymous visitors only) ----------- */
.bm-chat-email {
  margin-top: 8px;
}

.bm-chat-email-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;

  padding: 0;
  border: 0;
  background: transparent;

  font-family: inherit;
  font-size: 12px;
  line-height: 1.3;
  color: rgba(255, 255, 255, 0.72);

  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: rgba(255, 255, 255, 0.35);
  text-underline-offset: 3px;
  transition: color 0.15s ease;
}

.bm-chat-email-toggle:hover {
  color: #ffffff;
}

.bm-chat-email-toggle:focus-visible {
  outline: 2px solid var(--bm-amber);
  outline-offset: 2px;
}

.bm-chat-email-toggle svg,
.bm-chat-email-thanks svg {
  color: var(--bm-amber);
  flex: 0 0 auto;
}

.bm-chat-email-hint {
  margin-top: 6px;
  font-size: 11.5px;
  line-height: 1.4;
  color: rgba(255, 255, 255, 0.62);
}

.bm-chat-email-form {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 7px;
}

.bm-chat-email-input {
  flex: 1 1 auto;
  min-width: 0;

  padding: 7px 10px;
  /* !important throughout: the host site's global input styles otherwise win the
     cascade and force the field transparent (dark-on-navy) — see v0.6.2 note. */
  border: 1px solid #d6dbe3 !important;
  border-radius: 8px;

  font-family: inherit;
  font-size: 13px !important;
  line-height: 1.3;
  color: var(--bm-ink, #1a2433) !important;
  background: #ffffff !important;
}

.bm-chat-email-input::placeholder {
  color: rgba(26, 36, 51, 0.5) !important;
  opacity: 1;
}

/* Keep typed text dark even when the browser autofills (avoids white-on-white). */
.bm-chat-email-input:-webkit-autofill,
.bm-chat-email-input:-webkit-autofill:hover,
.bm-chat-email-input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--bm-ink, #1a2433) !important;
  -webkit-box-shadow: 0 0 0 1000px #ffffff inset !important;
  caret-color: var(--bm-ink, #1a2433);
}

.bm-chat-email-input:focus {
  outline: none;
  border-color: var(--bm-amber) !important;
  box-shadow: 0 0 0 2px rgba(244, 163, 0, 0.25);
}

.bm-chat-email-input:disabled {
  /* Saved state stays fully legible (white bg, dark text), not greyed out. */
  opacity: 1;
}

.bm-chat-email-submit {
  flex: 0 0 auto;
  padding: 7px 12px;
  border: 0;
  border-radius: 8px;

  background: var(--bm-amber);
  color: var(--bm-navy);

  font-family: inherit;
  font-size: 12.5px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transition: filter 0.15s ease;
}

.bm-chat-email-submit:hover:not(:disabled) {
  filter: brightness(0.95);
}

.bm-chat-email-submit:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 2px;
}

.bm-chat-email-submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.bm-chat-email-msg {
  margin-top: 6px;
  font-size: 12px;
  line-height: 1.35;
}

.bm-chat-email-msg-ok {
  color: var(--bm-amber);
}

.bm-chat-email-msg-err {
  color: #ffb4a8;
}

.bm-chat-email-thanks {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  line-height: 1.35;
  color: rgba(255, 255, 255, 0.85);
}

/* ---- Messages ---------------------------------------------------------- */
.bm-chat-messages {
  flex: 1 1 auto;
  min-height: 120px;
  overflow-y: auto;

  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;

  background: #f9fafb;
}

.bm-chat-row {
  display: flex;
}

.bm-chat-row-user {
  justify-content: flex-end;
}

.bm-chat-row-assistant {
  justify-content: flex-start;
}

.bm-chat-bubble {
  max-width: 85%;
  padding: 10px 13px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.45;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.bm-chat-bubble-user {
  background: rgba(244, 163, 0, 0.16);
  color: var(--bm-ink);
  border-bottom-right-radius: 4px;
}

.bm-chat-bubble-assistant {
  background: #eef1f5;
  color: var(--bm-ink);
  border-bottom-left-radius: 4px;
}

/* ---- Sources ----------------------------------------------------------- */
.bm-chat-sources {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--bm-line);
}

.bm-chat-sources-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--bm-muted);
  margin-bottom: 4px;
}

.bm-chat-sources-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.bm-chat-source-item {
  font-size: 12.5px;
  line-height: 1.35;
}

.bm-chat-source-link {
  color: var(--bm-amber);
  text-decoration: none;
}

.bm-chat-source-link:hover {
  text-decoration: underline;
}

.bm-chat-contact-line {
  margin-top: 6px;
  font-size: 13px;
}

/* ---- Thinking dots ----------------------------------------------------- */
.bm-chat-thinking {
  display: inline-flex;
  align-items: center;
}

.bm-chat-dots {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}

.bm-chat-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--bm-muted);
  opacity: 0.4;
  animation: bm-chat-pulse 1.2s infinite ease-in-out;
}

.bm-chat-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.bm-chat-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes bm-chat-pulse {
  0%, 80%, 100% {
    opacity: 0.4;
    transform: scale(0.85);
  }
  40% {
    opacity: 1;
    transform: scale(1);
  }
}

/* ---- Footer ------------------------------------------------------------ */
.bm-chat-footer {
  flex: 0 0 auto;
  padding: 12px;
  border-top: 1px solid var(--bm-line);
  background: var(--bm-surface);
}

.bm-chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.bm-chat-textarea {
  flex: 1 1 auto;
  resize: none;
  min-height: 38px;
  max-height: 96px;
  overflow-y: auto;

  padding: 9px 11px;
  border: 1px solid var(--bm-line);
  border-radius: 10px;

  font-family: inherit;
  font-size: 14px;
  line-height: 1.4;
  color: var(--bm-ink);
  background: #ffffff;
}

.bm-chat-textarea::placeholder {
  color: var(--bm-muted);
}

.bm-chat-textarea:focus {
  outline: none;
  border-color: var(--bm-amber);
  box-shadow: 0 0 0 2px rgba(244, 163, 0, 0.25);
}

.bm-chat-textarea:disabled {
  background: #f1f3f6;
  color: var(--bm-muted);
  cursor: not-allowed;
}

.bm-chat-send {
  flex: 0 0 auto;
  padding: 10px 16px;
  border: 0;
  border-radius: 10px;

  background: var(--bm-amber);
  color: var(--bm-navy);

  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.1s ease;
}

.bm-chat-send:hover:not(:disabled) {
  filter: brightness(0.95);
}

.bm-chat-send:active:not(:disabled) {
  transform: translateY(1px);
}

.bm-chat-send:focus-visible {
  outline: 2px solid var(--bm-navy);
  outline-offset: 2px;
}

.bm-chat-send:disabled {
  background: #d7dbe1;
  color: #9aa4b1;
  cursor: not-allowed;
}

.bm-chat-disclaimer {
  margin-top: 8px;
  font-size: 11px;
  line-height: 1.35;
  color: var(--bm-muted);
  text-align: center;
}

/* ---- Mobile bottom sheet ----------------------------------------------- */
@media (max-width: 480px) {
  .bm-chat-panel {
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    max-height: 85vh;
    border-radius: 14px 14px 0 0;
  }

  .bm-chat-launcher {
    bottom: 16px;
    right: 16px;
  }
}

/* ---- Reduced motion ---------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .bm-chat-launcher,
  .bm-chat-send,
  .bm-chat-close {
    transition: none;
  }
  .bm-chat-launcher:hover {
    transform: none;
  }
  .bm-chat-dot {
    animation: none;
    opacity: 0.6;
  }
}
