/*
 * Noriva AI assistant widget — modern, glassy, RTL, light/dark aware.
 *
 * Everything is scoped under .nvai and sets its own font/color/line-height, so
 * an unknown host page can neither bleed styles in nor have ours leak out. The
 * few animations all answer a user action (open, send, record, a new message)
 * except one subtle launcher ring, and every one is disabled under
 * prefers-reduced-motion at the bottom of the file.
 */
.nvai, .nvai * { box-sizing: border-box; }

.nvai {
  /* signature */
  --nv-violet-700: #6d28d9;
  --nv-violet-500: #8b5cf6;
  --nv-grad: linear-gradient(135deg, #7c3aed 0%, #6366f1 52%, #8b5cf6 100%);
  --nv-online: #34d399;

  /* surfaces + ink */
  --nv-fg: #1b1a2e;
  --nv-muted: #7a7692;
  --nv-surface: #ffffff;
  --nv-glass: rgba(255, 255, 255, .82);
  --nv-bot: #f2f0fb;
  --nv-border: rgba(24, 22, 46, .09);
  --nv-shadow: 0 24px 60px -14px rgba(39, 20, 86, .38), 0 8px 22px -10px rgba(39, 20, 86, .25);
  --nv-radius: 22px;

  position: fixed; inset-inline-end: 20px; inset-block-end: 20px;
  z-index: 2147483000; direction: rtl;
  font-family: Vazirmatn, Vazir, system-ui, "Segoe UI", Tahoma, sans-serif;
  font-size: 14px; line-height: 1.7; color: var(--nv-fg);
  text-align: start; letter-spacing: normal;
  -webkit-font-smoothing: antialiased;
}
@media (prefers-color-scheme: dark) {
  .nvai:not([data-theme="light"]) {
    --nv-fg: #ece9f6;
    --nv-muted: #9a93b8;
    --nv-surface: #171524;
    --nv-glass: rgba(23, 21, 36, .86);
    --nv-bot: #272340;
    --nv-border: rgba(255, 255, 255, .09);
    --nv-shadow: 0 24px 60px -12px rgba(0, 0, 0, .6), 0 8px 22px -10px rgba(0, 0, 0, .5);
  }
}
.nvai[data-theme="dark"] {
  --nv-fg: #ece9f6;
  --nv-muted: #9a93b8;
  --nv-surface: #171524;
  --nv-glass: rgba(23, 21, 36, .86);
  --nv-bot: #272340;
  --nv-border: rgba(255, 255, 255, .09);
  --nv-shadow: 0 24px 60px -12px rgba(0, 0, 0, .6), 0 8px 22px -10px rgba(0, 0, 0, .5);
}

/* ── launcher ─────────────────────────────────────────────────────────── */
.nvai__fab {
  position: relative; width: 62px; height: 62px; border: none; cursor: pointer;
  padding: 0; border-radius: 50%; display: grid; place-items: center; color: #fff;
  background: var(--nv-grad);
  box-shadow: 0 14px 30px -6px rgba(99, 71, 214, .6), 0 4px 10px rgba(0, 0, 0, .18);
  transition: transform .25s cubic-bezier(.34, 1.56, .64, 1), box-shadow .25s;
}
.nvai__fab img {
  width: calc(100% - 6px); height: calc(100% - 6px); border-radius: 50%;
  object-fit: cover; box-shadow: 0 0 0 2px rgba(255, 255, 255, .65);
}
.nvai__fab svg { width: 27px; height: 27px; }
.nvai__fab:hover { transform: translateY(-3px) scale(1.05);
  box-shadow: 0 20px 40px -6px rgba(99, 71, 214, .7), 0 6px 14px rgba(0, 0, 0, .22); }
.nvai__fab:active { transform: translateY(-1px) scale(1); }
/* breathing ring — the one bit of idle motion, to draw the eye to the orb */
.nvai__fab::before {
  content: ""; position: absolute; inset: -3px; border-radius: 50%;
  border: 2px solid var(--nv-violet-500); opacity: .5;
  animation: nv-ring 2.8s ease-out infinite;
}
/* live presence dot */
.nvai__fab::after {
  content: ""; position: absolute; inset-block-start: 3px; inset-inline-end: 3px;
  width: 13px; height: 13px; border-radius: 50%; background: var(--nv-online);
  border: 2.5px solid #fff;
}
.nvai[data-open="1"] .nvai__fab::before { display: none; }
@keyframes nv-ring { 0% { transform: scale(1); opacity: .5; } 70% { opacity: 0; } 100% { transform: scale(1.5); opacity: 0; } }

/* ── panel ────────────────────────────────────────────────────────────── */
.nvai__panel {
  position: absolute; inset-inline-end: 0; inset-block-end: 78px;
  width: min(380px, calc(100vw - 32px));
  height: min(600px, calc(100dvh - 120px));
  background: var(--nv-glass);
  -webkit-backdrop-filter: blur(22px) saturate(150%);
  backdrop-filter: blur(22px) saturate(150%);
  border: 1px solid var(--nv-border); border-radius: var(--nv-radius);
  box-shadow: var(--nv-shadow);
  display: none; flex-direction: column; overflow: hidden;
  transform-origin: bottom right;
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .nvai__panel { background: var(--nv-surface); }
}
.nvai[data-open="1"] .nvai__panel { display: flex; animation: nv-pop .34s cubic-bezier(.34, 1.28, .5, 1); }
@keyframes nv-pop { from { opacity: 0; transform: translateY(16px) scale(.95); } to { opacity: 1; transform: none; } }

/* ── header ───────────────────────────────────────────────────────────── */
.nvai__head {
  position: relative; display: flex; align-items: center; gap: 12px;
  padding: 15px 16px; color: #fff; background: var(--nv-grad);
}
.nvai__head > div { min-width: 0; }
.nvai__head::after {   /* soft specular highlight, top-start */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(120% 90% at 85% -20%, rgba(255, 255, 255, .25), transparent 60%);
}
.nvai__avatar {
  position: relative; width: 46px; height: 46px; border-radius: 50%; flex: none;
  display: grid; place-items: center; background: rgba(255, 255, 255, .22);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, .55), 0 4px 10px rgba(0, 0, 0, .2);
  transition: transform .2s ease, box-shadow .2s ease, filter .2s ease;
}
.nvai__avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.nvai__avatar span { font-size: 22px; line-height: 1; }
.nvai__avatar::after {   /* presence dot */
  content: ""; position: absolute; inset-block-end: -1px; inset-inline-end: -1px;
  width: 12px; height: 12px; border-radius: 50%; background: var(--nv-online);
  border: 2px solid #fff;
}
/* mouth: hidden unless speaking (the old one drew a permanent black bar) */
.nvai__mouth {
  position: absolute; inset-block-end: 9px; inset-inline-start: 50%; translate: -50% 0;
  width: 13px; height: 3px; border-radius: 3px; background: rgba(0, 0, 0, .42);
  opacity: 0; transition: opacity .2s;
}
.nvai[data-speaking="1"] .nvai__mouth { opacity: 1; animation: nv-talk .22s infinite alternate; }
.nvai[data-speaking="1"] .nvai__avatar {
  box-shadow: 0 0 0 3px rgba(255, 255, 255, .7), 0 0 0 8px rgba(255, 255, 255, .22);
}
@keyframes nv-talk { from { height: 3px; } to { height: 9px; } }

.nvai__name { font-weight: 700; font-size: 15.5px; letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nvai__status { display: flex; align-items: center; gap: 6px; font-size: 11.5px; opacity: .92; margin-top: 2px; }
.nvai__status::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--nv-online);
  box-shadow: 0 0 0 3px rgba(52, 211, 153, .3); animation: nv-breathe 2s ease-in-out infinite;
}
@keyframes nv-breathe { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }

.nvai__head-actions { margin-inline-start: auto; display: flex; gap: 6px; }
.nvai__iconbtn {
  background: rgba(255, 255, 255, .16); border: none; color: #fff; cursor: pointer;
  width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center;
  transition: background .15s, transform .12s;
}
.nvai__iconbtn:hover { background: rgba(255, 255, 255, .3); }
.nvai__iconbtn:active { transform: scale(.9); }
.nvai__iconbtn[aria-pressed="true"] { background: #fff; color: var(--nv-violet-700); }
.nvai__iconbtn svg { width: 17px; height: 17px; }

/* emotes — a light reaction on the avatar */
.nvai[data-emote="happy"]     .nvai__avatar { transform: scale(1.05); }
.nvai[data-emote="excited"]   .nvai__avatar { animation: nv-bounce .5s 2; }
.nvai[data-emote="thinking"]  .nvai__avatar { filter: grayscale(.3) brightness(.97); }
.nvai[data-emote="surprised"] .nvai__avatar { transform: scale(1.09); }
.nvai[data-emote="sad"]       .nvai__avatar { filter: brightness(.92) saturate(.85); }
@keyframes nv-bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }

/* ── messages ─────────────────────────────────────────────────────────── */
.nvai__body {
  flex: 1; overflow-y: auto; padding: 18px 16px; display: flex; flex-direction: column;
  gap: 11px; background: transparent; scroll-behavior: smooth; overscroll-behavior: contain;
}
.nvai__body::-webkit-scrollbar { width: 6px; }
.nvai__body::-webkit-scrollbar-thumb { background: rgba(124, 58, 237, .28); border-radius: 999px; }
.nvai__body::-webkit-scrollbar-track { background: transparent; }

.nvai__msg {
  max-width: 84%; padding: 10px 14px; border-radius: 18px; font-size: 14px; line-height: 1.75;
  white-space: pre-wrap; word-break: break-word; position: relative;
  box-shadow: 0 1px 2px rgba(20, 10, 40, .06);
  animation: nv-msg .3s ease both;
}
@keyframes nv-msg { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
.nvai__msg--bot { align-self: flex-start; background: var(--nv-bot); color: var(--nv-fg); border-start-start-radius: 6px; }
.nvai__msg--me  { align-self: flex-end; background: var(--nv-grad); color: #fff; border-start-end-radius: 6px;
  box-shadow: 0 4px 14px -3px rgba(99, 71, 214, .45); }

.nvai__typing { display: inline-flex; gap: 5px; padding: 3px 2px; }
.nvai__typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--nv-muted); animation: nv-blink 1.2s infinite ease-in-out; }
.nvai__typing i:nth-child(2) { animation-delay: .2s; }
.nvai__typing i:nth-child(3) { animation-delay: .4s; }
@keyframes nv-blink { 0%, 100% { opacity: .3; transform: translateY(0); } 50% { opacity: 1; transform: translateY(-2px); } }

/* ── action chips (cart / links) ─────────────────────────────────────── */
.nvai__chips { display: flex; flex-wrap: wrap; gap: 7px; align-self: flex-start; max-width: 92%; animation: nv-msg .3s ease both; }
.nvai__chip {
  border: 1.5px solid rgba(124, 58, 237, .32); color: var(--nv-violet-700);
  background: rgba(124, 58, 237, .05); border-radius: 999px; padding: 7px 14px;
  font-size: 13px; font-family: inherit; cursor: pointer; text-decoration: none;
  transition: background .15s, border-color .15s, transform .12s;
}
.nvai__chip:hover { background: rgba(124, 58, 237, .11); border-color: var(--nv-violet-500); }
.nvai__chip:active { transform: scale(.96); }
.nvai__chip--solid { background: var(--nv-grad); color: #fff; border-color: transparent;
  box-shadow: 0 4px 14px -3px rgba(99, 71, 214, .45); }
.nvai__chip--solid:hover { filter: brightness(1.06); background: var(--nv-grad); }
.nvai[data-theme="dark"] .nvai__chip {
  color: #c4b5fd; border-color: rgba(167, 139, 250, .4); background: rgba(167, 139, 250, .08);
}
@media (prefers-color-scheme: dark) {
  .nvai:not([data-theme="light"]) .nvai__chip {
    color: #c4b5fd; border-color: rgba(167, 139, 250, .4); background: rgba(167, 139, 250, .08);
  }
  .nvai:not([data-theme="light"]) .nvai__chip--solid { color: #fff; }
}

/* ── composer ─────────────────────────────────────────────────────────── */
.nvai__foot {
  display: flex; align-items: flex-end; gap: 8px; padding: 12px;
  border-top: 1px solid var(--nv-border); background: var(--nv-glass);
}
.nvai__input {
  flex: 1; border: 1.5px solid var(--nv-border); background: var(--nv-surface); color: var(--nv-fg);
  border-radius: 16px; padding: 11px 14px; font: inherit; font-size: 14px; line-height: 1.6;
  resize: none; max-height: 92px; transition: border-color .15s, box-shadow .15s;
}
.nvai__input:focus { outline: none; border-color: var(--nv-violet-500); box-shadow: 0 0 0 3px rgba(124, 58, 237, .15); }
.nvai__input::placeholder { color: var(--nv-muted); }
.nvai__send {
  background: var(--nv-grad); color: #fff; border: none; border-radius: 14px;
  width: 44px; height: 44px; cursor: pointer; flex: none; display: grid; place-items: center;
  box-shadow: 0 6px 16px -5px rgba(99, 71, 214, .55);
  transition: transform .14s, box-shadow .15s, opacity .15s;
}
.nvai__send svg { width: 19px; height: 19px; transform: scaleX(-1); }  /* point toward send in RTL */
.nvai__send:hover:not(:disabled) { transform: translateY(-2px) scale(1.04); }
.nvai__send:active:not(:disabled) { transform: scale(.94); }
.nvai__send:disabled { opacity: .4; cursor: default; box-shadow: none; }
.nvai__foot .nvai__iconbtn { background: var(--nv-bot); color: var(--nv-fg); width: 44px; height: 44px; border-radius: 14px; }
.nvai__foot .nvai__iconbtn:hover { background: rgba(124, 58, 237, .12); color: var(--nv-violet-700); }
.nvai__foot .nvai__iconbtn svg { width: 18px; height: 18px; }
.nvai__mic[aria-pressed="true"] { background: #ef4444; color: #fff; animation: nv-rec 1.3s infinite; }
@keyframes nv-rec { 0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, .5); } 50% { box-shadow: 0 0 0 7px rgba(239, 68, 68, 0); } }

/* ── phone ────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .nvai { inset-inline-end: 14px; inset-block-end: 14px; }
  .nvai__panel { width: calc(100vw - 24px); height: min(78dvh, calc(100dvh - 92px)); inset-block-end: 74px; }
  .nvai__fab { width: 58px; height: 58px; }
}

/* ── respect reduced motion ──────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .nvai *, .nvai *::before, .nvai *::after { animation: none !important; transition: none !important; }
}
