/* Breakaway Matcha chatbot widget styles. Scoped to #breakaway-bot to avoid
   bleeding into the host theme. Uses CSS variables for easy color tweaks. */

#breakaway-bot {
  --bb-primary: #1f6b6b;
  --bb-primary-dark: #134848;
  --bb-cream: #faf7f1;
  --bb-ink: #1d2424;
  --bb-rule: #d9d2c4;
  --bb-user-bg: #1f6b6b;
  --bb-user-text: #ffffff;
  --bb-bot-bg: #f0ede4;
  --bb-bot-text: #1d2424;
  --bb-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);

  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--bb-ink);
}

#breakaway-bot * { box-sizing: border-box; }

/* Launcher button */
#breakaway-bot .bb-launcher {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--bb-primary);
  color: white;
  border: none;
  cursor: pointer;
  box-shadow: var(--bb-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999998;
  transition: transform 0.15s ease, background 0.15s ease;
}
#breakaway-bot .bb-launcher:hover {
  background: var(--bb-primary-dark);
  transform: scale(1.05);
}

/* Panel */
#breakaway-bot .bb-panel {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 120px);
  background: white;
  border-radius: 12px;
  box-shadow: var(--bb-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 999999;
  border: 1px solid var(--bb-rule);
}
#breakaway-bot .bb-panel[hidden] { display: none; }

#breakaway-bot .bb-header {
  background: var(--bb-primary-dark);
  color: white;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
#breakaway-bot .bb-header-title { font-size: 15px; font-weight: 600; }
#breakaway-bot .bb-close {
  background: transparent;
  border: none;
  color: white;
  cursor: pointer;
  padding: 4px;
  display: flex;
  border-radius: 4px;
  transition: background 0.15s ease;
}
#breakaway-bot .bb-close:hover { background: rgba(255, 255, 255, 0.12); }

/* Messages */
#breakaway-bot .bb-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bb-cream);
}
#breakaway-bot .bb-msg {
  padding: 10px 14px;
  border-radius: 16px;
  max-width: 80%;
  white-space: pre-wrap;
  word-wrap: break-word;
}
#breakaway-bot .bb-msg-user {
  align-self: flex-end;
  background: var(--bb-user-bg);
  color: var(--bb-user-text);
  border-bottom-right-radius: 4px;
}
#breakaway-bot .bb-msg-assistant {
  align-self: flex-start;
  background: var(--bb-bot-bg);
  color: var(--bb-bot-text);
  border-bottom-left-radius: 4px;
}

#breakaway-bot .bb-typing {
  display: flex;
  gap: 4px;
  padding: 14px 16px;
}
#breakaway-bot .bb-typing span {
  width: 6px;
  height: 6px;
  background: var(--bb-primary);
  border-radius: 50%;
  animation: bb-bounce 1.2s infinite ease-in-out;
}
#breakaway-bot .bb-typing span:nth-child(2) { animation-delay: 0.2s; }
#breakaway-bot .bb-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bb-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Form */
#breakaway-bot .bb-form {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--bb-rule);
  background: white;
}
#breakaway-bot .bb-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--bb-rule);
  border-radius: 8px;
  padding: 8px 12px;
  font: inherit;
  color: inherit;
  background: white;
  outline: none;
  max-height: 120px;
  min-height: 36px;
}
#breakaway-bot .bb-input:focus { border-color: var(--bb-primary); }

#breakaway-bot .bb-send {
  background: var(--bb-primary);
  color: white;
  border: none;
  border-radius: 8px;
  width: 40px;
  height: 36px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: flex-end;
  transition: background 0.15s ease;
}
#breakaway-bot .bb-send:hover { background: var(--bb-primary-dark); }
#breakaway-bot .bb-send:disabled { background: #ccc; cursor: not-allowed; }

/* Footer */
#breakaway-bot .bb-footer {
  font-size: 11px;
  color: #888;
  padding: 8px 16px 10px;
  text-align: center;
  background: white;
  border-top: 1px solid var(--bb-rule);
}

/* Mobile */
@media (max-width: 480px) {
  /* Launcher: bigger thumb-friendly target, respect iOS home-indicator
   * safe area so the button isn't sitting inside the system gesture
   * zone (which makes it feel "untappable" on iPhone X+). The
   * env(safe-area-inset-bottom) value is ~34px on devices with a home
   * indicator and 0 on older ones. */
  #breakaway-bot .bb-launcher {
    right: calc(16px + env(safe-area-inset-right, 0px));
    bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    width: 60px;
    height: 60px;
  }
  /* Panel sits above the launcher with the same safe-area adjustment
   * so it doesn't get clipped by the home indicator on iOS. */
  #breakaway-bot .bb-panel {
    width: calc(100vw - 16px);
    right: 8px;
    bottom: calc(92px + env(safe-area-inset-bottom, 0px));
    height: calc(100vh - 110px - env(safe-area-inset-bottom, 0px));
  }
}

/* ===== Markdown-rendered content in assistant messages ===== */
#breakaway-bot .bb-msg-assistant p {
  margin: 0 0 8px 0;
}
#breakaway-bot .bb-msg-assistant p:last-child {
  margin-bottom: 0;
}
#breakaway-bot .bb-msg-assistant ul {
  margin: 0 0 8px 0;
  padding-left: 20px;
}
#breakaway-bot .bb-msg-assistant li {
  margin: 0 0 4px 0;
}
#breakaway-bot .bb-msg-assistant strong {
  font-weight: 600;
}
#breakaway-bot .bb-msg-assistant em {
  font-style: italic;
}
#breakaway-bot .bb-msg-assistant a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: rgba(0, 0, 0, 0.3);
  text-underline-offset: 2px;
}
#breakaway-bot .bb-msg-assistant a:hover {
  text-decoration-color: currentColor;
}

/* Product card image — sits at the top of a product block, full-width,
   contained aspect, with a subtle border. */
#breakaway-bot .bb-product-img {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  max-height: 220px;
  object-fit: cover;
  border-radius: 10px;
  margin: 8px 0 6px 0;
  background: #f4f4f0;
  border: 1px solid rgba(0, 0, 0, 0.06);
}

/* ===== Suggested-prompt chips (under greeting on first turn) ===== */
#breakaway-bot .bb-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 4px 0 12px 0;
  align-self: flex-start;
  max-width: 100%;
}
#breakaway-bot .bb-chip {
  appearance: none;
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 13px;
  font-family: inherit;
  line-height: 1.2;
  color: inherit;
  cursor: pointer;
  transition: background-color 0.12s ease, border-color 0.12s ease;
  white-space: nowrap;
}
#breakaway-bot .bb-chip:hover {
  background: #f4f4f0;
  border-color: rgba(0, 0, 0, 0.3);
}
#breakaway-bot .bb-chip:active {
  transform: translateY(1px);
}

/* Mobile: chips wrap and allow line breaks if the text is too long */
@media (max-width: 480px) {
  #breakaway-bot .bb-chip {
    white-space: normal;
    font-size: 12px;
  }
}

/* ===== "New chat" button in header + inline CTA on token-cap error ===== */
#breakaway-bot .bb-new-chat {
  appearance: none;
  background: transparent;
  border: none;
  padding: 6px;
  margin-left: auto;
  margin-right: 4px;
  cursor: pointer;
  color: inherit;
  opacity: 0.7;
  display: inline-flex;
  align-items: center;
  border-radius: 6px;
  transition: opacity 0.12s, background-color 0.12s;
}
#breakaway-bot .bb-new-chat:hover {
  opacity: 1;
  background-color: rgba(0, 0, 0, 0.06);
}
#breakaway-bot .bb-inline-cta {
  margin: 8px 0 0 0;
  display: flex;
  align-self: flex-start;
}
