/* Nexus Chat widget — floating text + voice chat (LiveKit).
   Self-contained: every rule is scoped under .nxc-*. Colours/fonts come from the
   theme tokens (--primary, --foreground, --border, --font-family) with the v3
   values as fallbacks, so it follows the store look without touching other sheets.
   Logical properties (inset-inline-*) make it flip correctly in AR/RTL. */

.nxc-root {
  --nxc-accent: var(--primary, #7C3AED);
  --nxc-accent-hover: var(--awan-accent-hover, #6D28D9);
  --nxc-on-accent: var(--primary-foreground, #FFFFFF);
  --nxc-bg: var(--background, #FFFFFF);
  --nxc-surface: var(--secondary, #F5F5F7);
  --nxc-ink: var(--foreground, #1D1D1F);
  --nxc-muted: var(--muted-foreground, #6E6E73);
  --nxc-border: var(--border, #D2D2D7);
  --nxc-ring: var(--ring, rgba(124, 58, 237, 0.35));
  --nxc-danger: #ef4444;        /* fills / borders */
  --nxc-danger-text: #B91C1C;   /* text on --nxc-bg: 6.5:1 (the fill colour is only 3.8:1) */
  --nxc-wa: #0E7C66;            /* WhatsApp-style green, 5.1:1 with white text */
  --nxc-wa-hover: #0B6B5E;
  position: fixed;
  inset-block-end: var(--nxc-bottom, 20px);   /* override hooks, e.g. .nxc-root { --nxc-bottom: 110px } if the */
  inset-inline-end: var(--nxc-side, 20px);    /* store's loyalty "Rewards" button sits in the same corner */
  z-index: 1045; /* above sticky/fixed (1030), below modal (1050) */
  font-family: var(--font-family, 'Inter', 'IBM Plex Sans Arabic', -apple-system, BlinkMacSystemFont, sans-serif);
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: 0;
  color: var(--nxc-ink);
}
html.dark .nxc-root {
  --nxc-bg: #10142A;
  --nxc-surface: #161C36;
  --nxc-ink: #F4F5FA;
  --nxc-muted: #A9AECB;
  --nxc-border: rgba(167, 139, 250, 0.2);
  --nxc-danger-text: #F87171;   /* 6.6:1 on the dark panel */
}
.nxc-root *, .nxc-root *::before, .nxc-root *::after { box-sizing: border-box; }
.nxc-root button, .nxc-root input { font: inherit; color: inherit; }
.nxc-root [hidden] { display: none !important; }

/* ── Launcher ── */
.nxc-launcher {
  width: 56px; height: 56px; border-radius: 50%; border: 0; cursor: pointer;
  display: grid; place-items: center;
  background: var(--nxc-accent); color: var(--nxc-on-accent);
  box-shadow: 0 8px 24px rgba(124, 58, 237, 0.35);
  transition: transform .2s ease, background-color .2s ease, box-shadow .2s ease;
}
.nxc-launcher:hover { background: var(--nxc-accent-hover); transform: translateY(-2px); }
.nxc-launcher:focus-visible, .nxc-btn:focus-visible, .nxc-close:focus-visible,
.nxc-sound:focus-visible, .nxc-limit-wa:focus-visible, .nxc-log:focus-visible {
  outline: 3px solid var(--nxc-ring); outline-offset: 2px;
}
.nxc-head .nxc-close:focus-visible { outline-color: #fff; }
.nxc-launcher svg { width: 26px; height: 26px; }
.nxc-root.nxc-open .nxc-launcher { display: none; }

/* ── Panel ── */
.nxc-panel {
  position: absolute; inset-block-end: 0; inset-inline-end: 0;
  width: min(380px, calc(100vw - 32px));
  height: min(560px, calc(100dvh - 40px));
  display: none; flex-direction: column; overflow: hidden;
  background: var(--nxc-bg); border: 1px solid var(--nxc-border); border-radius: 20px;
  box-shadow: 0 20px 50px -12px rgba(29, 29, 31, 0.28);
}
.nxc-root.nxc-open .nxc-panel { display: flex; animation: nxc-in .22s ease-out; }
@keyframes nxc-in { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }

.nxc-head {
  display: flex; align-items: center; gap: 10px; padding: 14px 16px;
  background: var(--nxc-accent); color: var(--nxc-on-accent);
}
.nxc-head-title { flex: 1; font-weight: 600; font-size: 15px; }
.nxc-head-sub { display: block; font-weight: 400; font-size: 12px; opacity: .85; }
.nxc-close {
  width: 32px; height: 32px; border: 0; border-radius: 50%; cursor: pointer;
  background: rgba(255, 255, 255, 0.18); color: inherit; display: grid; place-items: center;
}
.nxc-close:hover { background: rgba(255, 255, 255, 0.3); }
.nxc-close svg { width: 16px; height: 16px; }

/* ── Face: the avatar's live video for its leased minute, the host's portrait otherwise ── */
.nxc-face {
  position: relative; flex: none; overflow: hidden; background: #0b0b0d;
  aspect-ratio: 1 / 1; max-height: min(380px, 46dvh); border-bottom: 1px solid var(--nxc-border);
}
.nxc-face[hidden] { display: none; }
.nxc-face-video, .nxc-face-portrait { display: block; width: 100%; height: 100%; object-fit: cover; }
.nxc-face-video[hidden], .nxc-face-portrait[hidden] { display: none; }
.nxc-face-portrait { transform-origin: 50% 40%; object-position: 50% 0%; }
.nxc-face-video { object-position: 50% 30%; }
.nxc-face[data-mode="portrait"][data-state="speaking"] .nxc-face-portrait { animation: nxc-breathe 1.6s ease-in-out infinite; }
.nxc-face[data-mode="portrait"][data-state="thinking"] .nxc-face-portrait { filter: saturate(.85); }
@keyframes nxc-breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.03); } }
.nxc-face-tag {
  position: absolute; inset-inline-start: 10px; inset-block-end: 8px; padding: 3px 9px; border-radius: 980px;
  font-size: 11px; font-weight: 600; line-height: 1.4; color: #fff; background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); pointer-events: none;
}
.nxc-face-timer {
  position: absolute; inset-inline-end: 10px; inset-block-start: 8px; padding: 3px 9px; border-radius: 980px;
  font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; color: #fff; background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); pointer-events: none; direction: ltr;
}
.nxc-face-timer[hidden] { display: none; }
.nxc-call {
  position: absolute; inset-inline-end: 10px; inset-block-end: 8px; display: inline-flex; align-items: center; gap: 6px;
  min-height: 36px; padding: 6px 14px; border: 0; border-radius: 980px; cursor: pointer; font: inherit; font-size: 13px; font-weight: 700;
  background: var(--nxc-accent); color: var(--nxc-on-accent); box-shadow: 0 6px 18px -6px rgba(0, 0, 0, 0.5);
}
.nxc-call svg { width: 16px; height: 16px; }
.nxc-call:hover { filter: brightness(1.08); }
.nxc-call[hidden] { display: none; }
.nxc-root.nxc-has-face .nxc-panel { height: min(800px, calc(100dvh - 40px)); }
.nxc-root.nxc-has-face .nxc-log { min-height: 140px; }
@media (max-width: 480px) { .nxc-face { max-height: 42dvh; } }
@media (prefers-reduced-motion: reduce) { .nxc-face-portrait { animation: none !important; } }

/* ── Messages ── */
.nxc-log {
  flex: 1; min-height: 72px; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px;
  background: var(--nxc-surface); overscroll-behavior: contain;
}
.nxc-msg {
  max-width: 85%; padding: 10px 14px; border-radius: 16px; word-wrap: break-word;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.nxc-msg-bot { align-self: flex-start; background: var(--nxc-bg); border: 1px solid var(--nxc-border); border-end-start-radius: 4px; }
.nxc-msg-user { align-self: flex-end; background: var(--nxc-accent); color: var(--nxc-on-accent); border-end-end-radius: 4px; }
.nxc-msg-error { border-color: var(--nxc-danger); color: var(--nxc-danger-text); }
.nxc-msg-sys {
  align-self: center; max-width: 92%; padding: 2px 8px; text-align: center; font-size: 12px; line-height: 1.5;
  background: transparent; border: 0; color: var(--nxc-muted);
}
.nxc-msg-user.nxc-msg-voice { border-end-end-radius: 4px; }
.nxc-msg.nxc-interim { opacity: .7; }
.nxc-typing { display: inline-flex; gap: 4px; align-items: center; }
.nxc-typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--nxc-muted); animation: nxc-dot 1s infinite ease-in-out; }
.nxc-typing i:nth-child(2) { animation-delay: .15s; }
.nxc-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes nxc-dot { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* ── Quota strip (questions / voice time left, connection note) ── */
.nxc-quota {
  padding: 6px 16px; font-size: 12px; line-height: 1.5; text-align: center; font-weight: 500;
  color: var(--nxc-muted); background: var(--nxc-bg); border-bottom: 1px solid var(--nxc-border);
  font-variant-numeric: tabular-nums;
}
.nxc-limited .nxc-quota { color: var(--nxc-ink); }

/* ── "Tap to turn on sound" banner (autoplay policy fallback) ── */
.nxc-sound {
  flex: none; margin: 0 12px 8px; min-height: 40px; padding: 8px 14px; border-radius: 980px; cursor: pointer;
  border: 1px solid var(--nxc-accent); background: var(--nxc-bg); color: var(--nxc-accent); font-weight: 600;
}
.nxc-sound:hover { background: var(--nxc-surface); }

/* ── Voice mode strip (listening / hearing / thinking / speaking) ── */
.nxc-voice {
  flex: none; display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 8px 16px; border-top: 1px solid var(--nxc-border); background: var(--nxc-bg);
  font-size: 13px; font-weight: 500; color: var(--nxc-ink);
}
.nxc-bars { display: inline-flex; align-items: center; gap: 3px; height: 22px; }
.nxc-bars i {
  display: block; width: 4px; height: 6px; border-radius: 2px; background: var(--nxc-accent);
  transform-origin: center; animation: nxc-bar 1.6s infinite ease-in-out;
}
.nxc-bars i:nth-child(2) { animation-delay: .12s; }
.nxc-bars i:nth-child(3) { animation-delay: .24s; }
.nxc-bars i:nth-child(4) { animation-delay: .36s; }
.nxc-bars i:nth-child(5) { animation-delay: .48s; }
@keyframes nxc-bar { 0%, 100% { height: 6px; opacity: .5; } 50% { height: 12px; opacity: 1; } }
.nxc-voice[data-state="hearing"] .nxc-bars i { animation-duration: .6s; background: var(--nxc-danger); }
.nxc-voice[data-state="thinking"] .nxc-bars i { animation-duration: 1.1s; opacity: .8; }
.nxc-voice[data-state="speaking"] .nxc-bars i { animation-duration: .7s; }
.nxc-voice[data-state="speaking"] .nxc-bars i:nth-child(odd) { height: 16px; }
@keyframes nxc-bar-speak { 0%, 100% { height: 8px; } 50% { height: 22px; } }
.nxc-voice[data-state="speaking"] .nxc-bars i { animation-name: nxc-bar-speak; }

/* ── Limit reached card ── */
.nxc-limit {
  flex: 0 1 auto; display: flex; flex-direction: column; align-items: stretch; gap: 8px; padding: 12px 16px;
  max-height: 55%; overflow-y: auto; border-top: 1px solid var(--nxc-border); background: var(--nxc-bg);
}
.nxc-limit-text { margin: 0; font-size: 13.5px; white-space: pre-wrap; overflow-wrap: anywhere; }
.nxc-limit-wa {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; flex: none; min-height: 44px; padding: 0 18px;
  border-radius: 980px; background: var(--nxc-wa); color: #fff; font-weight: 600; text-decoration: none;
  transition: background-color .2s ease;
}
.nxc-limit-wa:hover { background: var(--nxc-wa-hover); color: #fff; }
.nxc-limit-wa svg { width: 20px; height: 20px; flex: none; }
.nxc-msg-wa { display: flex; margin-top: 10px; min-height: 40px; font-size: 14px; }   /* the same button inside an error bubble */
.nxc-limited .nxc-form { opacity: .75; }   /* composer stays visible but disabled once the limit is reached */

/* ── Composer ── */
.nxc-form { display: flex; align-items: center; gap: 8px; padding: 12px; border-top: 1px solid var(--nxc-border); background: var(--nxc-bg); }
.nxc-input {
  flex: 1; min-width: 0; height: 44px; padding: 0 16px; border-radius: 980px;
  border: 1px solid var(--nxc-border); background: var(--nxc-surface); outline: none;
}
.nxc-input::placeholder { color: var(--nxc-muted); }
.nxc-input:focus-visible { border-color: var(--nxc-accent); box-shadow: 0 0 0 3px var(--nxc-ring); }
.nxc-input:disabled { opacity: .6; cursor: not-allowed; }
.nxc-btn {
  flex: none; width: 44px; height: 44px; border-radius: 50%; border: 0; cursor: pointer;
  display: grid; place-items: center; transition: background-color .2s ease, transform .15s ease;
}
.nxc-btn svg { width: 20px; height: 20px; }
.nxc-btn[disabled] { opacity: .45; cursor: not-allowed; }
.nxc-send { background: var(--nxc-accent); color: var(--nxc-on-accent); }
.nxc-send:not([disabled]):hover { background: var(--nxc-accent-hover); }
html[dir="rtl"] .nxc-send svg { transform: scaleX(-1); }
.nxc-mic { background: var(--nxc-surface); color: var(--nxc-ink); border: 1px solid var(--nxc-border); }
.nxc-mic:not([disabled]):hover { border-color: var(--nxc-accent); color: var(--nxc-accent); }
.nxc-mic[hidden] { display: none; }
.nxc-mic.nxc-listening { background: var(--nxc-danger); border-color: var(--nxc-danger); color: #fff; animation: nxc-pulse 1.2s infinite; }
@keyframes nxc-pulse { 0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, .5); } 100% { box-shadow: 0 0 0 12px rgba(239, 68, 68, 0); } }

.nxc-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (max-width: 480px) {
  .nxc-root { inset-block-end: var(--nxc-bottom, 12px); inset-inline-end: var(--nxc-side, 12px); }
  .nxc-panel { width: calc(100vw - 24px); height: min(600px, calc(100dvh - 24px)); }
  .nxc-input { font-size: 16px; } /* stops iOS zoom-on-focus */
}
/* Momo 5 sticky buy bar (.m3-buybar on the home page, #m5p-sticky on the product page since v1.0.16; fixed to the bottom on phones, z-index 60): keep the closed launcher
   above it so it never covers the Buy button. The open panel is a dialog and may cover it. */
@media (max-width: 900px) {
  body:has(.m3-buybar.is-visible, .m5p-sticky.is-show) .nxc-root:not(.nxc-open) {
    inset-block-end: calc(var(--nxc-bottom, 12px) + 68px + env(safe-area-inset-bottom, 0px));
  }
}
@supports not selector(:has(*)) { /* very old browsers: always lift on phones, product pages included */
  @media (max-width: 900px) {
    .nxc-root:not(.nxc-open) { inset-block-end: calc(var(--nxc-bottom, 12px) + 68px + env(safe-area-inset-bottom, 0px)); }
  }
}
@media (prefers-reduced-motion: reduce) {
  .nxc-root *, .nxc-root *::before, .nxc-root *::after { animation: none !important; transition: none !important; }
  .nxc-bars i { height: 12px; }
}

/* ── Floating host (11 Oct v1.0.15): a round face in the bottom-left corner, phone button to call,
      tap the face for the chat. Pinned to the physical LEFT on both Arabic and English pages. ── */
.nxc-root.nxc-has-dock { inset-inline-end: auto; inset-inline-start: auto; left: var(--nxc-side, 20px); right: auto; }
.nxc-root.nxc-has-dock .nxc-launcher { display: none; }
.nxc-root.nxc-has-dock .nxc-panel {
  inset-inline-end: auto; left: 0; right: auto;
  inset-block-end: auto; bottom: calc(100% + 14px);
  height: min(520px, calc(100dvh - 222px));
}
.nxc-root.nxc-has-dock.nxc-in-call .nxc-panel { height: min(520px, calc(100dvh - 294px)); }
/* 24 Oct v1.0.18: the host is bigger (his word: "too small"): 96 -> 128 px, in a call 156 -> 200 px; phone 84 -> 112, 132 -> 168. */
.nxc-dock { position: relative; width: 128px; height: 128px; transition: width .25s ease, height .25s ease; }
.nxc-root.nxc-in-call .nxc-dock { width: 200px; height: 200px; }
.nxc-dock .nxc-face {
  width: 100%; height: 100%; aspect-ratio: auto; max-height: none; border: 0; border-radius: 50%;
  background: transparent; cursor: pointer; box-shadow: 0 12px 32px -10px rgba(0, 0, 0, 0.45);
}
.nxc-dock .nxc-face:focus-visible { outline: 3px solid var(--nxc-ring); outline-offset: 3px; }
.nxc-dock .nxc-face-portrait { object-position: 50% 12%; }
.nxc-dock .nxc-face-video { object-position: 50% 30%; }
.nxc-dock .nxc-face-timer { inset-inline-end: auto; left: 50%; transform: translateX(-50%); inset-block-start: 10px; font-size: 12px; padding: 2px 9px; }
.nxc-dock .nxc-call {
  position: absolute; inset-inline-end: auto; inset-block-end: auto; right: -2px; bottom: -2px; /* logical resets first: after them they won the cascade and dropped the button below the face */
  width: 52px; height: 52px; min-height: 0; padding: 0; gap: 0; border: 3px solid #fff; border-radius: 50%;
  display: grid; place-items: center; background: #16A34A; color: #fff; box-shadow: 0 6px 16px -4px rgba(22, 163, 74, 0.6);
  animation: nxc-ring 2.4s ease-in-out infinite;
}
.nxc-dock .nxc-call svg { width: 24px; height: 24px; }
.nxc-dock .nxc-call.nxc-call-end { background: #DC2626; box-shadow: 0 6px 16px -4px rgba(220, 38, 38, 0.6); animation: none; }
.nxc-dock .nxc-call.nxc-call-end svg { transform: rotate(135deg); }
@keyframes nxc-ring { 0%, 70%, 100% { transform: none; } 75% { transform: rotate(-14deg); } 80% { transform: rotate(14deg); } 85% { transform: rotate(-10deg); } 90% { transform: rotate(8deg); } }
.nxc-dock-close { /* a 44 px tap target (the store's button rule forced 44 px anyway) drawn as a 28 px disc */
  position: absolute; left: -10px; top: -10px; width: 44px; height: 44px; min-width: 0; min-height: 0; padding: 0; border: 0; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer; background: transparent; color: #fff; opacity: .85;
}
.nxc-dock-close::before { content: ""; position: absolute; inset: 8px; border-radius: 50%; background: rgba(29, 29, 31, 0.72); box-shadow: 0 0 0 1.5px rgba(255, 255, 255, 0.55); }
.nxc-dock-close svg { position: relative; width: 13px; height: 13px; }
.nxc-dock-close:hover { opacity: 1; }
.nxc-root.nxc-in-call .nxc-dock-close { display: none; }
@media (max-width: 480px) {
  .nxc-dock { width: 112px; height: 112px; }
  .nxc-root.nxc-in-call .nxc-dock { width: 168px; height: 168px; }
  .nxc-dock .nxc-call { width: 48px; height: 48px; }
  /* centred on the screen (12 px each side) although the host sits at the left edge */
  .nxc-root.nxc-has-dock .nxc-panel { left: calc(12px - var(--nxc-side, 20px)); width: calc(100vw - 24px); height: min(480px, calc(100dvh - 198px)); }
  .nxc-root.nxc-has-dock.nxc-in-call .nxc-panel { height: min(440px, calc(100dvh - 256px)); }
}
@media (prefers-reduced-motion: reduce) { .nxc-dock, .nxc-dock .nxc-call { animation: none !important; transition: none !important; } }

/* the floating host stays above the Buy bar even while the chat is open */
@media (max-width: 900px) {
  body:has(.m3-buybar.is-visible, .m5p-sticky.is-show) .nxc-root.nxc-has-dock { inset-block-end: calc(var(--nxc-bottom, 12px) + 84px + env(safe-area-inset-bottom, 0px)); }
  body:has(.m3-buybar.is-visible, .m5p-sticky.is-show) .nxc-root.nxc-has-dock .nxc-panel { height: min(480px, calc(100dvh - 278px)); }
  body:has(.m3-buybar.is-visible, .m5p-sticky.is-show) .nxc-root.nxc-has-dock.nxc-in-call .nxc-panel { height: min(420px, calc(100dvh - 336px)); }
}
/* the product page's buy bar (#m5p-sticky, 73 px) also shows on wide screens after a scroll: lift the host above it there too */
@media (min-width: 901px) {
  body:has(.m5p-sticky.is-show) .nxc-root.nxc-has-dock { inset-block-end: calc(var(--nxc-bottom, 20px) + 84px); }
  body:has(.m5p-sticky.is-show) .nxc-root.nxc-has-dock .nxc-panel { height: min(520px, calc(100dvh - 306px)); }
  body:has(.m5p-sticky.is-show) .nxc-root.nxc-has-dock.nxc-in-call .nxc-panel { height: min(520px, calc(100dvh - 378px)); }
}
