/* ==========================================================================
   Arena Finance chat widget — messenger-style UI
   Self-contained: every rule is scoped under .afc
   ========================================================================== */

.afc {
  --afc-blue: #0084ff;
  --afc-blue-dark: #0073e0;
  --afc-grey: #f0f2f5;
  --afc-bubble: #f0f0f0;
  --afc-text: #050505;
  --afc-muted: #65676b;
  --afc-line: #e4e6eb;
  --afc-green: #31a24c;
  --afc-red: #f02849;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI Historic", "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.3334;
  color: var(--afc-text);
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 2147483000;
  -webkit-font-smoothing: antialiased;
}
.afc *, .afc *::before, .afc *::after { box-sizing: border-box; }
.afc button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; margin: 0; }
.afc p { margin: 0; }
.afc svg { display: block; }
.afc :focus-visible { outline: 2px solid var(--afc-blue); outline-offset: 2px; }

/* ---------- Launcher ---------- */
.afc-launcher {
  position: relative;
  display: inline-flex; align-items: center; gap: 10px;
  height: 56px; padding: 0 22px 0 18px !important;
  border-radius: 28px;
  background: linear-gradient(135deg, #00b2ff 0%, #006aff 100%) !important;
  color: #fff !important;
  font-size: 16px !important; font-weight: 600;
  box-shadow: 0 6px 20px rgba(0, 106, 255, .4), 0 2px 6px rgba(0, 0, 0, .12);
  transition: transform .18s cubic-bezier(.2, .8, .2, 1), box-shadow .18s, opacity .18s;
}
.afc-launcher:hover { transform: translateY(-2px) scale(1.02); box-shadow: 0 10px 26px rgba(0, 106, 255, .46), 0 2px 6px rgba(0, 0, 0, .12); }
.afc-launcher:active { transform: scale(.97); }
.afc-launcher svg { width: 28px; height: 28px; }
.afc-open .afc-launcher { opacity: 0; transform: scale(.6); pointer-events: none; }

.afc-badge {
  position: absolute; top: -4px; right: -2px;
  min-width: 22px; height: 22px; padding: 0 6px;
  display: none; align-items: center; justify-content: center;
  border-radius: 11px; border: 2px solid #fff;
  background: var(--afc-red); color: #fff;
  font-size: 12px; font-weight: 700; line-height: 1;
}
.afc-has-unread .afc-badge { display: inline-flex; }

/* ---------- Teaser bubble ---------- */
.afc-teaser {
  position: absolute; right: 0; bottom: 72px;
  width: max-content; max-width: 270px;
  display: flex; align-items: flex-start; gap: 8px;
  padding: 12px 10px 12px 14px;
  background: #fff; border-radius: 18px 18px 4px 18px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .18), 0 0 0 1px rgba(0, 0, 0, .04);
  font-size: 14.5px;
  opacity: 0; transform: translateY(8px); pointer-events: none;
  transition: opacity .25s, transform .25s;
}
.afc-teaser.afc-show { opacity: 1; transform: none; pointer-events: auto; }
.afc-open .afc-teaser { display: none; }
.afc-teaser-text { cursor: pointer; text-align: left; }
.afc-teaser-close { flex: none; width: 22px; height: 22px; border-radius: 50%; color: var(--afc-muted) !important; display: flex; align-items: center; justify-content: center; }
.afc-teaser-close:hover { background: var(--afc-grey); }
.afc-teaser-close svg { width: 12px; height: 12px; }

/* ---------- Panel ---------- */
.afc-panel {
  position: absolute; right: 0; bottom: 0;
  width: min(540px, calc(100vw - 48px)); height: min(820px, calc(100vh - 48px)); height: min(820px, calc(100dvh - 48px));
  display: flex; flex-direction: column;
  background: #fff; border-radius: 16px; overflow: hidden;
  box-shadow: 0 12px 28px rgba(0, 0, 0, .2), 0 2px 4px rgba(0, 0, 0, .1), 0 0 0 1px rgba(0, 0, 0, .04);
  transform-origin: bottom right;
  opacity: 0; visibility: hidden; transform: translateY(16px) scale(.94);
  transition: opacity .2s, transform .22s cubic-bezier(.2, .8, .2, 1), visibility 0s .22s;
}
.afc-open .afc-panel { opacity: 1; visibility: visible; transform: none; transition-delay: 0s; }

/* Header */
.afc-header {
  position: relative; z-index: 2; flex: none;
  display: flex; align-items: center; gap: 10px;
  padding: 14px 12px 14px 18px;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .1), 0 0 0 1px rgba(0, 0, 0, .03);
}
.afc-avatar { position: relative; flex: none; width: 48px; height: 48px; }
.afc-avatar svg { width: 100%; height: 100%; border-radius: 50%; }
.afc-avatar-dot {
  position: absolute; right: -1px; bottom: -1px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--afc-green); border: 2px solid #fff;
}
.afc-title { flex: 1; min-width: 0; }
.afc-name { font-size: 18px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.afc-status { font-size: 13px; color: var(--afc-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.afc-icon-btn {
  flex: none; width: 40px; height: 40px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--afc-blue) !important;
  transition: background .12s;
}
.afc-icon-btn:hover { background: rgba(0, 0, 0, .06); }
.afc-icon-btn svg { width: 24px; height: 24px; }

.afc-menu {
  position: absolute; top: 64px; right: 56px; z-index: 3;
  min-width: 200px; padding: 6px;
  background: #fff; border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .2), 0 0 0 1px rgba(0, 0, 0, .05);
  display: none;
}
.afc-menu.afc-show { display: block; }
.afc-menu button { display: block; width: 100%; padding: 9px 10px; border-radius: 6px; text-align: left; font-size: 14.5px; font-weight: 500; }
.afc-menu button:hover { background: var(--afc-grey); }

/* Preview-mode strip */
.afc-demo {
  flex: none; padding: 7px 14px;
  background: #fff8e1; border-bottom: 1px solid #f4e3a6;
  color: #6b5300; font-size: 12px; text-align: center;
}

/* Message list */
.afc-body {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  padding: 20px 18px 10px;
  scrollbar-width: thin; scrollbar-color: #c8ccd1 transparent;
}
.afc-intro { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 16px 16px 28px; }
.afc-intro .afc-avatar { width: 96px; height: 96px; margin-bottom: 12px; }
.afc-intro-name { font-size: 20px; font-weight: 700; }
.afc-intro-sub { margin-top: 2px; font-size: 14px; color: var(--afc-muted); }

.afc-time { margin: 14px 0 8px; text-align: center; font-size: 12px; font-weight: 500; color: var(--afc-muted); }

.afc-row { display: flex; align-items: flex-end; gap: 8px; margin-top: 2px; }
.afc-row.afc-gap { margin-top: 10px; }
.afc-row.afc-me { justify-content: flex-end; }
.afc-row .afc-avatar { width: 32px; height: 32px; }
.afc-row .afc-avatar.afc-ghost { visibility: hidden; }

.afc-bubble {
  max-width: 75%;
  padding: 9px 14px;
  font-size: 16px;
  border-radius: 20px;
  white-space: pre-wrap; overflow-wrap: anywhere;
  animation: afc-pop .18s cubic-bezier(.2, .8, .2, 1);
}
.afc-them .afc-bubble { background: var(--afc-bubble); color: var(--afc-text); }
.afc-me .afc-bubble { background: var(--afc-blue); color: #fff; }

/* Grouped corners, as in messenger threads */
.afc-them.afc-first .afc-bubble { border-bottom-left-radius: 4px; }
.afc-them.afc-mid .afc-bubble { border-top-left-radius: 4px; border-bottom-left-radius: 4px; }
.afc-them.afc-last .afc-bubble { border-top-left-radius: 4px; }
.afc-me.afc-first .afc-bubble { border-bottom-right-radius: 4px; }
.afc-me.afc-mid .afc-bubble { border-top-right-radius: 4px; border-bottom-right-radius: 4px; }
.afc-me.afc-last .afc-bubble { border-top-right-radius: 4px; }

/* Emoji-only messages render large, without a bubble */
.afc-row.afc-emoji .afc-bubble { background: none; padding: 2px 0; font-size: 34px; line-height: 1.15; border-radius: 0; }

.afc-receipt { display: flex; justify-content: flex-end; align-items: center; gap: 4px; margin: 3px 2px 0 0; font-size: 11px; color: var(--afc-muted); }
.afc-receipt svg { width: 13px; height: 13px; }
.afc-receipt.afc-failed { color: var(--afc-red); }
.afc-receipt button { color: var(--afc-red) !important; font-size: 11px !important; font-weight: 600; text-decoration: underline; }

/* Typing indicator */
.afc-typing { display: inline-flex; align-items: center; gap: 4px; height: 36px; padding: 0 14px; border-radius: 18px; background: var(--afc-bubble); }
.afc-typing i { width: 8px; height: 8px; border-radius: 50%; background: #8a8d91; animation: afc-bounce 1.2s infinite ease-in-out; }
.afc-typing i:nth-child(2) { animation-delay: .15s; }
.afc-typing i:nth-child(3) { animation-delay: .3s; }

/* Quick replies */
.afc-quick { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin: 14px 0 4px; padding-left: 40px; }
.afc-quick button {
  padding: 9px 16px; border-radius: 20px;
  border: 1px solid var(--afc-blue) !important; background: #fff !important; color: var(--afc-blue) !important;
  font-size: 15px !important; font-weight: 600;
  transition: background .12s, color .12s;
}
.afc-quick button:hover { background: var(--afc-blue) !important; color: #fff !important; }

/* Emoji popover */
.afc-emoji-pop {
  position: absolute; right: 60px; bottom: 96px; z-index: 3;
  display: none; grid-template-columns: repeat(6, 36px); gap: 2px;
  padding: 8px; background: #fff; border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .2), 0 0 0 1px rgba(0, 0, 0, .05);
}
.afc-emoji-pop.afc-show { display: grid; }
.afc-emoji-pop button { width: 36px; height: 36px; border-radius: 8px; font-size: 22px !important; line-height: 1; }
.afc-emoji-pop button:hover { background: var(--afc-grey); }

/* Composer */
.afc-composer { flex: none; display: flex; align-items: flex-end; gap: 6px; padding: 10px 10px 6px 16px; background: #fff; }
.afc-inputwrap { position: relative; flex: 1; min-width: 0; background: var(--afc-grey); border-radius: 22px; }
.afc-input {
  display: block; width: 100%; height: 44px; max-height: 130px; margin: 0;
  padding: 11px 46px 11px 16px;
  border: 0; outline: 0; resize: none; background: transparent;
  font: inherit; font-size: 16px; line-height: 22px; color: var(--afc-text);
  scrollbar-width: thin;
}
.afc-input::placeholder { color: var(--afc-muted); opacity: 1; }
.afc-inputwrap:focus-within { box-shadow: 0 0 0 2px rgba(0, 132, 255, .25); }
.afc-emoji-btn { position: absolute; right: 4px; bottom: 2px; }
.afc-send svg { width: 28px; height: 28px; transition: transform .12s; }
.afc-send:active svg { transform: scale(.85); }

.afc-note { flex: none; padding: 2px 16px 12px; text-align: center; font-size: 12px; color: #8a8d91; }

@keyframes afc-pop { from { opacity: 0; transform: translateY(6px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes afc-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .6; } 30% { transform: translateY(-4px); opacity: 1; } }

/* ---------- Phones: full-screen sheet ---------- */
@media (max-width: 520px) {
  .afc { right: 16px; bottom: 16px; }
  .afc-panel {
    position: fixed; inset: 0; width: 100%; height: 100%; height: 100dvh;
    border-radius: 0; transform-origin: bottom center; transform: translateY(24px);
  }
  .afc-header { padding-top: max(10px, env(safe-area-inset-top)); }
  .afc-input { font-size: 16px; } /* prevents iOS zoom on focus */
  .afc-note { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .afc-bubble { max-width: 78%; }
  html.afc-lock, html.afc-lock body { overflow: hidden; }
}

@media (prefers-reduced-motion: reduce) {
  .afc *, .afc-panel, .afc-launcher { animation: none !important; transition: none !important; }
}

/* ---------- Attachments ---------- */
.afc-attach-btn { position: absolute; right: 42px; bottom: 2px; }
.afc-inputwrap.afc-has-attach .afc-input { padding-right: 92px; }
