/* First-party support-chat widget (replaces Crisp) — see docs/GUEST_SUPPORT_CHAT.md */

#ayi-support-bubble {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #3BD7CF;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
  z-index: 9998;
  overflow: hidden;
  transition: transform 0.15s ease;
}

#ayi-support-bubble:active {
  transform: scale(0.9);
}

/* Plays automatically whenever #ayi-support-panel's `display` flips from
   none to flex (toggle()/open() in support-widget.js) — no JS class
   toggling needed, browsers restart a CSS animation on that transition. */
@keyframes ayiSupportPanelPopIn {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* CS avatar photo (support_widget_avatar_url setting) — fills whichever
   circle it's placed in (bubble/header/message-row); falls back to
   AVATAR_SVG when unset, see applyAvatar() in support-widget.js. */
.ayi-support-avatar-img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

#ayi-support-panel {
  position: fixed;
  right: 20px;
  bottom: 90px;
  width: 360px;
  max-width: calc(100vw - 40px);
  height: 520px;
  max-height: calc(100vh - 140px);
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
  z-index: 9999;
  flex-direction: column;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  animation: ayiSupportPanelPopIn 0.18s ease-out;
  transform-origin: bottom right;
}

/* Embedded mode (resources/views/internal/support-chat-embed.blade.php) —
   a mobile app's WebView points straight at that page, so the "panel" IS
   the whole screen, always open, nothing floating on top of other content.
   Capped at a phone-ish width and centered rather than stretched edge-to-edge
   — on an actual WebView (already phone-width) the cap never kicks in; on a
   desktop browser it reads like a mobile app preview (SPA-style), not a
   wide, oddly-stretched panel. */
#ayi-support-panel.ayi-support-embedded {
  animation: none;
  position: static;
  width: 100%;
  max-width: 480px;
  height: 100vh;
  max-height: none;
  margin: 0 auto;
  border-radius: 0;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.08);
}

/* ─── Header ──────────────────────────────────────────────────────────── */

#ayi-support-header {
  background: #3BD7CF;
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.ayi-support-header-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

.ayi-support-header-text {
  flex: 1 1 auto;
  min-width: 0;
}

.ayi-support-title {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
}

.ayi-support-subtitle {
  font-size: 12px;
  opacity: 0.85;
  line-height: 1.2;
}

#ayi-support-header button {
  background: none;
  border: none;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
}

/* ─── Message thread ──────────────────────────────────────────────────── */

#ayi-support-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 14px;
  background: #fff;
}

.ayi-support-date-separator {
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: #94a3b8;
  margin: 10px 0 14px;
}

.ayi-support-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 10px;
}

.ayi-support-avatar-sm {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #3BD7CF;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

.ayi-support-avatar-sm svg {
  width: 16px;
  height: 16px;
}

.ayi-support-message {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 14px;
  margin-bottom: 8px;
  font-size: 14px;
  line-height: 1.4;
  word-wrap: break-word;
  white-space: pre-line;
}

.ayi-support-message.mine {
  background: #3BD7CF;
  color: #fff;
  margin-left: auto;
  border-bottom-right-radius: 4px;
}

.ayi-support-message.theirs {
  background: #f1f5f9;
  color: #1e293b;
  border-bottom-left-radius: 4px;
}

/* "Chat in Web App" CTA under a GuestRegistrationMessage reply — block-level
   so it sits on its own line below the text, matching every other reply's
   word-wrap: break-word; white-space: pre-line text above it. */
.ayi-support-cta-button {
  display: block;
  margin-top: 10px;
  background: #3BD7CF;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

/* Inline identify card — a "theirs" bubble that also holds the name/email
   form, so asking for identity reads as part of the conversation instead of
   a separate blocking screen. */
.ayi-support-message.ayi-support-card {
  max-width: 88%;
  background: #fff;
  border: 1px solid #e2e8f0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.ayi-support-card p {
  margin: 0 0 10px;
  font-size: 13px;
  color: #475569;
}

.ayi-support-card input {
  display: block;
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  margin-bottom: 8px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-size: 14px;
}

.ayi-support-card button,
#ayi-support-send {
  background: #3BD7CF;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.ayi-support-error {
  color: #dc2626;
  font-size: 12px;
  min-height: 16px;
  margin-bottom: 4px;
}

/* ─── "please identify" nudge banner ──────────────────────────────────── */

.ayi-support-banner {
  display: none;
  background: #fef3c7;
  color: #92400e;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  padding: 8px 12px;
}

/* ─── Composer ────────────────────────────────────────────────────────── */

#ayi-support-composer {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid #e2e8f0;
  background: #fff;
}

#ayi-support-emoji-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 4px;
}

#ayi-support-input {
  flex: 1 1 auto;
  padding: 9px 12px;
  border: 1px solid #e2e8f0;
  border-radius: 20px;
  font-size: 14px;
}

#ayi-support-input:disabled,
#ayi-support-send:disabled,
#ayi-support-emoji-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#ayi-support-send {
  border-radius: 20px;
}

/* Emoji picker — a small popover anchored above the composer. */
.ayi-support-emoji-picker {
  display: none;
  position: absolute;
  bottom: 100%;
  left: 10px;
  margin-bottom: 6px;
  width: 220px;
  max-height: 160px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  padding: 8px;
  grid-template-columns: repeat(6, 1fr);
  gap: 2px;
  z-index: 1;
}

.ayi-support-emoji-picker.open {
  display: grid;
}

.ayi-support-emoji-option {
  background: none;
  border: none;
  font-size: 18px;
  padding: 4px;
  border-radius: 6px;
  cursor: pointer;
}

.ayi-support-emoji-option:hover {
  background: #f1f5f9;
}

@media (max-width: 480px) {
  #ayi-support-panel {
    right: 10px;
    bottom: 80px;
    width: calc(100vw - 20px);
  }
}
