/* ویجت چت آنلاین فروشگاه — روشن/تیره، RTL، موبایل (v116) */
:root {
  --nc-z: 1100;
  --nc-bottom: 24px;
  --nc-side: 22px;
  --nc-bg: #ffffff;
  --nc-surface: #f4f6fa;
  --nc-border: rgba(20, 28, 48, 0.1);
  --nc-text: #1b2333;
  --nc-muted: #6c7589;
  --nc-accent: var(--brand, #0d7377);
  --nc-accent-rgb: var(--brand-rgb, 13, 115, 119);
  --nc-on-accent: #ffffff;
  --nc-mine: var(--nc-accent);
  --nc-mine-text: #ffffff;
  --nc-theirs: #eef1f6;
  --nc-theirs-text: #1b2333;
  --nc-head-from: var(--nc-accent);
  --nc-head-to: rgba(var(--nc-accent-rgb), 0.78);
  --nc-shadow: 0 24px 60px rgba(15, 20, 40, 0.22), 0 2px 8px rgba(15, 20, 40, 0.08);
  --nc-online: #22c55e;
  --nc-offline: #9aa3b5;
  --nc-tick: #8b94a8;
  --nc-tick-read: #38bdf8;
}
html[theme-color="dark"] {
  --nc-bg: #0e1a22;
  --nc-surface: #15262f;
  --nc-border: rgba(148, 163, 184, 0.16);
  --nc-text: #e8eef5;
  --nc-muted: #8fa3b3;
  --nc-accent: #2dd4bf;
  --nc-accent-rgb: 45, 212, 191;
  --nc-on-accent: #05211f;
  --nc-mine: #0f766e;
  --nc-mine-text: #f0fdfa;
  --nc-theirs: #1a2f3a;
  --nc-theirs-text: #e8eef5;
  --nc-head-from: #0f4c4a;
  --nc-head-to: #0b3b45;
  --nc-shadow: 0 24px 60px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(45, 212, 191, 0.14);
  --nc-tick: #7f95a6;
  --nc-tick-read: #5eead4;
}

/* ---------- دکمهٔ شناور ---------- */
.nc-launcher {
  position: fixed;
  inset-inline-end: var(--nc-side);
  right: var(--nc-side);
  left: auto;
  bottom: calc(var(--nc-bottom) + env(safe-area-inset-bottom, 0px));
  z-index: var(--nc-z);
  width: 56px;
  height: 56px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--nc-head-from), var(--nc-head-to));
  color: #fff;
  box-shadow: 0 10px 26px rgba(var(--nc-accent-rgb), 0.38), 0 2px 6px rgba(15, 20, 40, 0.18);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}
html[theme-color="dark"] .nc-launcher { color: #eafffb; box-shadow: 0 10px 28px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(45, 212, 191, 0.3); }
.nc-launcher:hover { transform: translateY(-2px) scale(1.04); }
.nc-launcher:focus-visible { outline: 3px solid rgba(var(--nc-accent-rgb), 0.55); outline-offset: 3px; }
.nc-launcher .nc-launcher-x { display: none; }
.nc-launcher.is-open .nc-launcher-ic { display: none; }
.nc-launcher.is-open .nc-launcher-x { display: inline; }
.nc-launcher::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid rgba(var(--nc-accent-rgb), 0.45);
  opacity: 0;
  pointer-events: none;
}
.nc-launcher.has-unread::after { animation: nc-pulse 2s ease-out infinite; }
@keyframes nc-pulse { 0% { opacity: 0.7; transform: scale(1); } 80%, 100% { opacity: 0; transform: scale(1.35); } }
.nc-launcher .nc-launcher-dot {
  position: absolute;
  bottom: 3px;
  inset-inline-start: 3px;
  left: 3px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--nc-offline);
  border: 2px solid var(--nc-bg);
}
.nc-launcher.is-online .nc-launcher-dot { background: var(--nc-online); }
.nc-launcher.is-idle .nc-launcher-dot { display: none; }
.nc-launcher .nc-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  left: auto;
  min-width: 21px;
  height: 21px;
  padding: 0 5px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 800;
  display: none;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--nc-bg);
  line-height: 1;
}
.nc-launcher .nc-badge.is-on { display: inline-flex; }

/* ---------- پنل ---------- */
.nc-panel {
  position: fixed;
  right: var(--nc-side);
  left: auto;
  bottom: calc(var(--nc-bottom) + 70px + env(safe-area-inset-bottom, 0px));
  z-index: calc(var(--nc-z) + 1);
  width: min(390px, calc(100vw - 24px));
  height: min(600px, calc(100vh - 130px));
  height: min(600px, calc(100dvh - 130px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 22px;
  background: var(--nc-bg);
  color: var(--nc-text);
  border: 1px solid var(--nc-border);
  box-shadow: var(--nc-shadow);
  opacity: 0;
  visibility: hidden;
  transform: translateY(14px) scale(0.97);
  transform-origin: bottom right;
  transition: opacity 0.2s ease, transform 0.22s ease, visibility 0s linear 0.22s;
  font-family: inherit;
}
.nc-panel.is-open { opacity: 1; visibility: visible; transform: none; transition-delay: 0s; }
.nc-panel * { box-sizing: border-box; }

.nc-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  background: linear-gradient(135deg, var(--nc-head-from), var(--nc-head-to));
  color: #fff;
}
.nc-head-main { display: flex; align-items: center; gap: 12px; min-width: 0; }
.nc-avatar {
  position: relative;
  flex: none;
  width: 42px; height: 42px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  display: grid; place-items: center;
  font-size: 1.1rem;
}
.nc-online-dot {
  position: absolute; bottom: 0; inset-inline-end: 0; right: 0;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--nc-offline);
  border: 2px solid var(--nc-head-from);
}
.nc-panel.is-online .nc-online-dot { background: var(--nc-online); box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.6); animation: nc-live 2s infinite; }
@keyframes nc-live { 70% { box-shadow: 0 0 0 7px rgba(34, 197, 94, 0); } 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); } }
.nc-head-copy { display: flex; flex-direction: column; min-width: 0; line-height: 1.5; }
.nc-head-copy strong { font-size: 1rem; font-weight: 800; }
.nc-head-copy .nc-status { font-size: 0.76rem; opacity: 0.9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nc-head-btn {
  flex: none; width: 36px; height: 36px; border: 0; border-radius: 50%;
  background: rgba(255, 255, 255, 0.16); color: #fff; cursor: pointer;
  display: grid; place-items: center; transition: background 0.15s;
}
.nc-head-btn:hover { background: rgba(255, 255, 255, 0.28); }

.nc-notice {
  flex: none; margin: 0; padding: 8px 14px; font-size: 0.78rem; line-height: 1.7;
  background: rgba(245, 158, 11, 0.14); color: #92520a; border-bottom: 1px solid rgba(245, 158, 11, 0.25);
}
html[theme-color="dark"] .nc-notice { color: #fcd9a0; background: rgba(245, 158, 11, 0.12); }
.nc-notice.is-error { background: rgba(239, 68, 68, 0.14); color: #b42323; border-color: rgba(239, 68, 68, 0.3); }
html[theme-color="dark"] .nc-notice.is-error { color: #fecaca; }

/* ---------- فرم مهمان (فقط ناشناس) ---------- */
.nc-guest-gate {
  flex: 1 1 auto; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding: 20px 18px;
  background: var(--nc-bg);
}
.nc-guest-gate[hidden] { display: none; }
.nc-guest-gate-copy strong { display: block; font-size: 1.02rem; font-weight: 800; margin-bottom: 4px; }
.nc-guest-gate-copy p { margin: 0; color: var(--nc-muted); font-size: 0.84rem; line-height: 1.8; }
.nc-field { display: flex; flex-direction: column; gap: 5px; margin: 0; }
.nc-field > span { font-size: 0.78rem; font-weight: 700; color: var(--nc-muted); }
.nc-field input {
  width: 100%; height: 46px; padding: 0 14px; border-radius: 12px; font-size: 16px; font-family: inherit;
  border: 1.5px solid var(--nc-border); background: var(--nc-surface); color: var(--nc-text); outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.nc-field input:focus { border-color: var(--nc-accent); box-shadow: 0 0 0 3px rgba(var(--nc-accent-rgb), 0.18); }
.nc-guest-error { margin: 0; color: #dc2626; font-size: 0.8rem; font-weight: 600; }
html[theme-color="dark"] .nc-guest-error { color: #fca5a5; }
.nc-guest-start {
  height: 48px; border: 0; border-radius: 14px; cursor: pointer; font-family: inherit;
  font-weight: 800; font-size: 0.95rem;
  background: var(--nc-accent); color: var(--nc-on-accent);
  box-shadow: 0 8px 18px rgba(var(--nc-accent-rgb), 0.3);
}
.nc-guest-start:active { transform: scale(0.98); }

/* ---------- بدنه ---------- */
.nc-chat-body { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; background: var(--nc-bg); }
.nc-chat-body.is-locked { display: none; }
.nc-messages {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  padding: 14px 14px 8px; display: flex; flex-direction: column; gap: 6px;
  background:
    radial-gradient(circle at 20% 0%, rgba(var(--nc-accent-rgb), 0.06), transparent 55%),
    var(--nc-bg);
  scrollbar-width: thin;
}
.nc-empty {
  margin: auto; text-align: center; color: var(--nc-muted); font-size: 0.86rem; line-height: 1.9;
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 16px;
}
.nc-empty strong { color: var(--nc-text); font-size: 1.05rem; }
.nc-empty-icon {
  width: 60px; height: 60px; border-radius: 50%; display: grid; place-items: center; font-size: 1.6rem;
  background: rgba(var(--nc-accent-rgb), 0.12); color: var(--nc-accent); margin-bottom: 6px;
}
.nc-starters { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 10px; }
.nc-starters button {
  border: 1px solid var(--nc-border); background: var(--nc-surface); color: var(--nc-text);
  border-radius: 999px; padding: 6px 14px; font-size: 0.8rem; font-family: inherit; cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.nc-starters button:hover { border-color: var(--nc-accent); color: var(--nc-accent); }

.nc-day { align-self: center; margin: 8px 0 4px; }
.nc-day span {
  display: inline-block; font-size: 0.7rem; padding: 2px 12px; border-radius: 999px;
  background: var(--nc-surface); color: var(--nc-muted); border: 1px solid var(--nc-border);
}

.nc-bubble {
  max-width: 82%; padding: 8px 12px 5px; border-radius: 16px; font-size: 0.9rem; line-height: 1.8;
  word-break: break-word; overflow-wrap: anywhere; position: relative;
  animation: nc-in 0.18s ease;
}
@keyframes nc-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
/* RTL: «مشتری» سمت راست، «پشتیبان» سمت چپ */
.nc-bubble.is-mine { align-self: flex-start; background: var(--nc-mine); color: var(--nc-mine-text); border-end-start-radius: 5px; }
.nc-bubble.is-staff:not(.is-mine) { align-self: flex-end; background: var(--nc-theirs); color: var(--nc-theirs-text); border-end-end-radius: 5px; }
.nc-bubble.is-failed { outline: 1.5px solid #ef4444; }
.nc-bubble-body { white-space: pre-wrap; }
.nc-bubble-meta {
  display: flex; align-items: center; gap: 5px; justify-content: flex-end; margin-top: 1px;
  font-size: 0.68rem; opacity: 0.78; direction: rtl;
}
.nc-bubble-meta time { font-variant-numeric: tabular-nums; }
.chat-ticks { display: inline-flex; align-items: center; }
.chat-tick { font-size: 0.62rem; color: currentColor; opacity: 0.85; display: inline-flex; }
.chat-tick.is-read { color: var(--nc-tick-read); opacity: 1; }
.chat-tick.is-read i + i { margin-inline-start: -5px; }
.chat-tick.is-failed { color: #ef4444; opacity: 1; }
.nc-bubble.is-mine .chat-tick.is-read { color: #7dd3fc; }
html[theme-color="dark"] .nc-bubble.is-mine .chat-tick.is-read { color: #5eead4; }
.nc-chat-img { display: block; max-width: 100%; max-height: 220px; border-radius: 12px; margin-top: 4px; }

/* دستیار هوشمند: لینک، کارت محصول، برچسب */
.chat-link { color: var(--nc-accent); font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.nc-bubble.is-mine .chat-link { color: inherit; }
.chat-bot-ic { font-size: 0.7rem; color: var(--nc-accent); }
.nc-bubble.has-cards { max-width: 92%; }
.chat-pcards {
  display: flex; gap: 8px; margin: 8px -4px 2px; padding: 2px 4px 6px;
  overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: thin; -webkit-overflow-scrolling: touch;
}
.chat-pcard {
  flex: 0 0 132px; scroll-snap-align: start; display: flex; flex-direction: column; gap: 4px;
  padding: 6px; border-radius: 12px; background: var(--nc-bg); border: 1px solid var(--nc-border);
  color: var(--nc-text); text-decoration: none; transition: transform 0.15s ease, border-color 0.15s ease;
}
.chat-pcard:hover { border-color: var(--nc-accent); transform: translateY(-2px); }
.chat-pcard-img {
  display: grid; place-items: center; aspect-ratio: 1; border-radius: 9px; overflow: hidden;
  background: var(--nc-surface); color: var(--nc-muted); font-size: 1.4rem;
}
.chat-pcard-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.chat-pcard-name {
  font-size: 0.76rem; font-weight: 700; line-height: 1.6; height: 3.2em; overflow: hidden;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.chat-pcard-price { font-size: 0.74rem; font-weight: 800; color: var(--nc-accent); font-variant-numeric: tabular-nums; }
.chat-pcard.is-out { opacity: 0.6; }
.chat-pcard.is-out .chat-pcard-price { color: var(--nc-muted); }
.nc-panel.has-ai .nc-avatar i::before { content: "\f544"; }
.nc-file {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 4px; padding: 6px 10px; border-radius: 10px;
  background: rgba(0, 0, 0, 0.12); color: inherit; text-decoration: none; font-size: 0.82rem;
}

.nc-typing { flex: none; padding: 2px 16px 6px; font-size: 0.74rem; color: var(--nc-muted); display: flex; align-items: center; gap: 8px; }
.nc-typing[hidden] { display: none; }
.nc-typing-dots { display: inline-flex; gap: 3px; }
.nc-typing-dots span { width: 5px; height: 5px; border-radius: 50%; background: var(--nc-accent); animation: nc-dot 1.1s infinite; }
.nc-typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.nc-typing-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes nc-dot { 0%, 60%, 100% { opacity: 0.3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }
.nc-closed-bar { flex: none; margin: 0 12px 6px; padding: 6px 10px; text-align: center; font-size: 0.75rem; color: var(--nc-muted); background: var(--nc-surface); border-radius: 10px; }
.nc-closed-bar[hidden] { display: none; }

.nc-emoji {
  display: none; flex: none; flex-wrap: wrap; gap: 2px; padding: 8px 10px; max-height: 120px; overflow-y: auto;
  border-top: 1px solid var(--nc-border); background: var(--nc-surface);
}
.nc-emoji.is-open { display: flex; }
.nc-emoji button { border: 0; background: transparent; font-size: 1.3rem; width: 36px; height: 34px; border-radius: 8px; cursor: pointer; }
.nc-emoji button:hover { background: rgba(var(--nc-accent-rgb), 0.14); }

.nc-composer {
  flex: none; display: flex; align-items: center; gap: 6px; margin: 0;
  padding: 10px 10px calc(10px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--nc-border); background: var(--nc-bg);
}
.nc-icon {
  flex: none; width: 38px; height: 38px; border: 0; border-radius: 50%; background: transparent; margin: 0;
  color: var(--nc-muted); font-size: 1.05rem; display: grid; place-items: center; cursor: pointer;
}
.nc-icon:hover { color: var(--nc-accent); background: rgba(var(--nc-accent-rgb), 0.1); }
.nc-composer input[type="text"] {
  flex: 1 1 auto; min-width: 0; height: 44px; padding: 0 14px; border-radius: 22px; font-family: inherit;
  font-size: 16px; border: 1.5px solid var(--nc-border); background: var(--nc-surface); color: var(--nc-text); outline: none;
}
.nc-composer input[type="text"]::placeholder { color: var(--nc-muted); }
.nc-composer input[type="text"]:focus { border-color: var(--nc-accent); box-shadow: 0 0 0 3px rgba(var(--nc-accent-rgb), 0.16); }
.nc-send {
  flex: none; width: 44px; height: 44px; border: 0; border-radius: 50%; cursor: pointer;
  background: var(--nc-surface); color: var(--nc-muted); font-size: 1rem; display: grid; place-items: center;
  transition: background 0.15s, color 0.15s, transform 0.1s;
}
.nc-send i { transform: scaleX(-1); } /* جهت RTL */
.nc-send.is-ready { background: var(--nc-accent); color: var(--nc-on-accent); box-shadow: 0 6px 14px rgba(var(--nc-accent-rgb), 0.35); }
.nc-send:disabled { cursor: default; }
.nc-send.is-ready:active { transform: scale(0.93); }

/* ---------- دسکتاپ / موبایل ---------- */
@media (max-width: 991.98px) {
  :root { --nc-side: 14px; --nc-bottom: 92px; }
  .nc-launcher { width: 52px; height: 52px; font-size: 1.3rem; }
  /* پنل تمام‌صفحه، بالاتر از نوار پایین */
  .nc-panel {
    inset: 0; right: 0; left: 0; bottom: 0; width: 100%; height: 100%; height: 100dvh;
    max-width: none; border-radius: 0; border: 0; z-index: 1600; transform: translateY(24px);
    transform-origin: bottom center;
  }
  html.nc-open .nc-launcher { display: none; }
  html.nc-open, html.nc-open body { overscroll-behavior: none; }
}
@media (min-width: 992px) { :root { --nc-bottom: 24px; } }
/* صفحه‌هایی با نوار خرید چسبان */
body.has-stickybuy .nc-launcher, body:has(.nh-stickybuy) .nc-launcher { --nc-bottom: 164px; }
@media (min-width: 992px) { body.has-stickybuy .nc-launcher, body:has(.nh-stickybuy) .nc-launcher { --nc-bottom: 24px; } }

@media (prefers-reduced-motion: reduce) {
  .nc-panel, .nc-bubble, .nc-launcher { transition: none; animation: none; }
  .nc-launcher.has-unread::after, .nc-panel.is-online .nc-online-dot, .nc-typing-dots span { animation: none; }
}
