/* Shagerd — storefront chat widget (Nirvana brand gradient) */

html.storefront {
  --chat-coral: #e8836b;
  --chat-gold: #e89b2a;
  --chat-blue: #3e7fbe;
  --chat-grad: linear-gradient(135deg, #e8836b 0%, #e89b2a 55%, #3e7fbe 100%);
  --chat-grad-warm: linear-gradient(135deg, #ed9a84 0%, #e8836b 45%, #e89b2a 100%);
  --chat-glow: rgba(232, 131, 107, 0.4);
  --chat-surface: #ffffff;
  --chat-bg: #f7f3ef;
  --chat-ink: #2e2a33;
  --chat-muted: rgba(46, 42, 51, 0.55);
  --chat-border: rgba(46, 42, 51, 0.1);
  --chat-shadow: 0 20px 50px rgba(232, 131, 107, 0.18), 0 8px 24px rgba(62, 127, 190, 0.1);
}

html.storefront.dark {
  --chat-surface: #252019;
  --chat-bg: #1a1714;
  --chat-ink: #ede8e3;
  --chat-muted: rgba(237, 232, 227, 0.58);
  --chat-border: rgba(255, 255, 255, 0.1);
  --chat-shadow: 0 20px 50px rgba(0, 0, 0, 0.5), 0 8px 24px rgba(0, 0, 0, 0.35);
}

.chat-widget {
  --chat-accent: var(--chat-coral);
  --chat-accent-mid: var(--chat-gold);
  --chat-accent-deep: var(--chat-blue);
  --chat-surface: #ffffff;
  --chat-bg: #f7f3ef;
  --chat-ink: #2e2a33;
  --chat-muted: rgba(46, 42, 51, 0.55);
  --chat-border: rgba(46, 42, 51, 0.1);
  --chat-shadow: 0 20px 50px rgba(232, 131, 107, 0.18), 0 8px 24px rgba(62, 127, 190, 0.1);
  position: fixed;
  inset-inline-end: 1.25rem;
  bottom: 1.25rem;
  z-index: 9999;
  font-family: "Vazirmatn", system-ui, sans-serif;
  pointer-events: none;
}

html.storefront.dark .chat-widget {
  --chat-surface: #252019;
  --chat-bg: #1a1714;
  --chat-ink: #ede8e3;
  --chat-muted: rgba(237, 232, 227, 0.58);
  --chat-border: rgba(255, 255, 255, 0.1);
  --chat-shadow: 0 20px 50px rgba(0, 0, 0, 0.5), 0 8px 24px rgba(0, 0, 0, 0.35);
}

.storefront-body:has(.store-buybar) .chat-widget {
  bottom: 5.5rem;
}

@media (min-width: 1024px) {
  .storefront-body:has(.store-buybar) .chat-widget {
    bottom: 1.25rem;
  }
}

.chat-widget.is-open {
  pointer-events: auto;
}

.chat-widget__launcher-wrap {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  pointer-events: auto;
  overflow: visible;
}

.chat-widget__hint-bubble {
  position: fixed;
  z-index: 10003;
  width: max-content;
  max-width: min(15.5rem, calc(100vw - 1.5rem));
  padding: 0.65rem 0.75rem 0.55rem;
  border-radius: 1rem;
  background: var(--chat-surface);
  border: 1px solid var(--chat-border);
  box-shadow: var(--chat-shadow);
  color: var(--chat-ink);
  pointer-events: auto;
}

.chat-widget__hint-bubble.is-visible {
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
}

.chat-widget__hint-bubble[hidden] {
  display: none !important;
}

.chat-widget__hint-bubble::after {
  content: "";
  position: absolute;
  bottom: -5px;
  left: var(--hint-arrow-x, 1.1rem);
  width: 10px;
  height: 10px;
  background: var(--chat-surface);
  border-right: 1px solid var(--chat-border);
  border-bottom: 1px solid var(--chat-border);
  transform: rotate(45deg);
}

.chat-widget__hint-bubble.is-below::after {
  bottom: auto;
  top: -5px;
  border-right: 1px solid var(--chat-border);
  border-bottom: none;
  border-top: 1px solid var(--chat-border);
  transform: rotate(225deg);
}

.chat-widget__hint-text {
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.55;
  color: var(--chat-muted);
}

.chat-widget__hint-text strong {
  color: var(--chat-coral);
  font-weight: 700;
}

.chat-widget__hint-cta {
  margin-top: 0.45rem;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--chat-coral);
  text-decoration: underline;
  text-underline-offset: 0.12em;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font-family: inherit;
}

.chat-widget__hint-close {
  position: absolute;
  top: 0.35rem;
  inset-inline-end: 0.35rem;
  width: 1.35rem;
  height: 1.35rem;
  border: none;
  border-radius: 999px;
  font-size: 0.7rem;
  line-height: 1;
  color: var(--chat-muted);
  background: rgba(46, 42, 51, 0.06);
  cursor: pointer;
}

html.storefront.dark .chat-widget__hint-close {
  background: rgba(255, 255, 255, 0.08);
}

/* ── Inline launcher (search row / header) ── */
.chat-widget__launch {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 3rem;
  padding: 0 1.1rem;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  background: var(--chat-grad);
  color: #fff;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 800;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow:
    0 8px 30px var(--chat-glow),
    inset 0 1px 0 rgba(255, 255, 255, 0.22);
  transition: transform 0.18s ease, box-shadow 0.18s ease, filter 0.18s ease;
}

.chat-widget__launch:hover {
  transform: translateY(-1px);
  filter: brightness(1.04);
  box-shadow:
    0 10px 34px rgba(232, 131, 107, 0.48),
    inset 0 1px 0 rgba(255, 255, 255, 0.28);
}

.chat-widget__launch.is-active {
  background: linear-gradient(145deg, #2e2a33, #1a1714);
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow: 0 4px 16px rgba(46, 42, 51, 0.25);
}

.chat-widget__launch svg {
  width: 1.35rem;
  height: 1.35rem;
  flex-shrink: 0;
}

@media (max-width: 480px) {
  .store-search__row .chat-widget__launch-label {
    display: none;
  }

  .store-search__row .chat-widget__launch {
    width: 3rem;
    padding: 0;
  }
}

/* ── Intro dialog ── */
.chat-widget__intro {
  position: fixed;
  inset: 0;
  z-index: 10000;
  margin: auto;
  padding: 0;
  border: 0;
  width: min(calc(100vw - 2rem), 22rem);
  max-height: calc(100vh - 2rem);
  overflow: visible;
  background: transparent;
  pointer-events: auto;
}

.chat-widget__intro::backdrop {
  background: rgba(46, 42, 51, 0.45);
  backdrop-filter: blur(4px);
}

html.storefront.dark .chat-widget__intro::backdrop {
  background: rgba(0, 0, 0, 0.62);
}

.chat-widget__intro-card {
  padding: 1.5rem;
  border-radius: 1.35rem;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: var(--chat-surface);
  box-shadow: 0 24px 60px rgba(46, 42, 51, 0.2);
  color: var(--chat-ink);
}

html.storefront.dark .chat-widget__intro-card {
  border-color: rgba(255, 255, 255, 0.1);
}

.chat-widget__intro-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 3rem;
  height: 3rem;
  margin-bottom: 0.85rem;
  border-radius: 999px;
  background: var(--chat-grad);
  color: #fff;
  box-shadow: 0 8px 24px var(--chat-glow);
}

.chat-widget__intro-badge svg {
  width: 1.4rem;
  height: 1.4rem;
}

.chat-widget__intro-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.45;
}

.chat-widget__intro-lead {
  margin: 0.55rem 0 0;
  font-size: 0.875rem;
  line-height: 1.75;
  color: var(--chat-muted);
}

.chat-widget__intro-steps {
  margin: 1rem 0 0;
  padding-inline-start: 1.15rem;
  font-size: 0.85rem;
  line-height: 1.8;
  color: var(--chat-ink);
}

.chat-widget__intro-steps li + li {
  margin-top: 0.35rem;
}

.chat-widget__intro-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 1.25rem;
}

.chat-widget__intro-start {
  min-height: 2.85rem;
  padding: 0.65rem 1rem;
  border: 0;
  border-radius: 999px;
  background: var(--chat-grad);
  color: #fff;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 8px 24px var(--chat-glow);
}

.chat-widget__intro-start:hover {
  filter: brightness(1.05);
}

.chat-widget__intro-skip {
  padding: 0.45rem;
  border: 0;
  background: transparent;
  color: var(--chat-muted);
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
}

.chat-widget__intro-skip:hover {
  color: var(--chat-ink);
}

/* ── Backdrop ── */
.chat-widget__backdrop {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(2px);
}

html.storefront.dark .chat-widget__backdrop {
  background: rgba(0, 0, 0, 0.55);
}

/* ── Window ── */
.chat-widget__window {
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 1;
  width: 24rem;
  max-width: calc(100vw - 2.5rem);
  height: 34rem;
  max-height: calc(100vh - 6rem);
  border-radius: 1.25rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: var(--chat-surface);
  box-shadow: var(--chat-shadow);
  overflow: hidden;
}

@media (max-width: 639px) {
  .chat-widget {
    inset-inline: 0.75rem;
    bottom: 5.5rem;
  }

  .chat-widget__window {
    width: 100%;
    max-width: none;
    height: min(34rem, calc(100vh - 7rem));
  }

  .storefront-body:has(.store-buybar) .chat-widget {
    bottom: 9.5rem;
  }
}

/* ── Header ── */
.chat-widget__header {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 1.125rem 1rem 1.35rem;
  background: var(--chat-grad);
  color: #fff;
  flex-shrink: 0;
  overflow: hidden;
}

.chat-widget__header-shine {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 15% 0%, rgba(255, 255, 255, 0.32), transparent 45%),
    radial-gradient(circle at 88% 110%, rgba(62, 127, 190, 0.28), transparent 42%);
}

.chat-widget__header::after {
  content: "";
  position: absolute;
  inset-inline: 0;
  bottom: 0;
  height: 0.65rem;
  background: var(--chat-bg);
  border-radius: 0.65rem 0.65rem 0 0;
}

.chat-widget__avatar {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.65rem;
  height: 2.65rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  border: 2px solid rgba(255, 255, 255, 0.35);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
  flex-shrink: 0;
}

.chat-widget__avatar svg {
  width: 1.25rem;
  height: 1.25rem;
}

.chat-widget__meta {
  position: relative;
  z-index: 1;
  flex: 1;
  min-width: 0;
}

.chat-widget__title {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.3;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

.chat-widget__status {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0.2rem 0 0;
  font-size: 0.78rem;
  opacity: 0.95;
}

.chat-widget__online {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 999px;
  background: #4ade80;
  box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.28);
  animation: chat-online-pulse 2s ease-in-out infinite;
}

@keyframes chat-online-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.65; }
}

.chat-widget__header-close {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.15rem;
  height: 2.15rem;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.15s;
}

.chat-widget__header-close:hover {
  background: rgba(255, 255, 255, 0.28);
  transform: scale(1.05);
}

.chat-widget__header-close svg {
  width: 1rem;
  height: 1rem;
}

/* ── Frame ── */
.chat-widget__frame-wrap {
  flex: 1;
  min-height: 0;
  background: var(--chat-bg);
}

.chat-widget__frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

body.chat-widget-open {
  overflow: hidden;
}

@media (prefers-reduced-motion: reduce) {
  .chat-widget__launch,
  .chat-widget__online {
    animation: none;
    transition: none;
  }
}

/* ── Embed (iframe interior) ── */
html.chat-embed {
  --chat-coral: #e8836b;
  --chat-gold: #e89b2a;
  --chat-blue: #3e7fbe;
  --chat-grad: linear-gradient(135deg, #e8836b 0%, #e89b2a 55%, #3e7fbe 100%);
  --chat-grad-warm: linear-gradient(135deg, #ed9a84 0%, #e8836b 45%, #e89b2a 100%);
  --chat-glow: rgba(232, 131, 107, 0.4);
}

html.chat-embed,
html.chat-embed body.chat-embed__body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #f7f3ef;
  color: #2e2a33;
  font-family: "Vazirmatn", system-ui, sans-serif;
  font-size: 14px;
  display: flex;
  flex-direction: column;
}

.chat-embed__messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  direction: ltr;
}

.chat-msg {
  display: flex;
}

.chat-msg--bot {
  justify-content: flex-start;
}

.chat-msg--user {
  justify-content: flex-end;
}

.chat-msg__bubble {
  max-width: 85%;
  padding: 0.625rem 0.875rem;
  border-radius: 1.125rem;
  line-height: 1.65;
  word-break: break-word;
  direction: rtl;
  text-align: right;
}

.chat-msg--bot .chat-msg__bubble {
  background: #fff;
  border: 1px solid rgba(46, 42, 51, 0.08);
  border-bottom-right-radius: 0.25rem;
  box-shadow: 0 2px 8px rgba(46, 42, 51, 0.04);
}

.chat-msg--user .chat-msg__bubble {
  background: var(--chat-grad-warm);
  color: #fff;
  border-bottom-left-radius: 0.25rem;
  box-shadow: 0 4px 14px rgba(232, 131, 107, 0.28);
}

.chat-msg__bubble .chat-msg__link {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 0.15em;
  font-weight: 700;
}

.chat-msg--bot .chat-msg__bubble .chat-msg__link {
  color: var(--chat-coral);
}

.chat-msg--user .chat-msg__bubble .chat-msg__link {
  color: #fff;
}

.chat-msg--typing .chat-msg__bubble {
  background: #fff;
  border: 1px solid rgba(46, 42, 51, 0.08);
  color: rgba(46, 42, 51, 0.45);
  font-style: italic;
}

.chat-embed__composer {
  --chat-coral: #e8836b;
  --chat-gold: #e89b2a;
  --chat-blue: #3e7fbe;
  --chat-grad: linear-gradient(135deg, #e8836b 0%, #e89b2a 55%, #3e7fbe 100%);
  --chat-glow: rgba(232, 131, 107, 0.4);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem;
  border-top: 1px solid rgba(46, 42, 51, 0.08);
  background: #fff;
  flex-shrink: 0;
}

.chat-embed__input {
  flex: 1;
  min-width: 0;
  padding: 0.7rem 1rem;
  border: 1px solid rgba(46, 42, 51, 0.12);
  border-radius: 999px;
  background: #f7f3ef;
  font: inherit;
  font-size: 0.875rem;
  line-height: 1.4;
  outline: none;
}

.chat-embed__input:focus {
  border-color: var(--chat-coral);
  box-shadow: 0 0 0 3px rgba(232, 131, 107, 0.18);
}

.chat-embed__attach,
.chat-embed__send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  min-width: 2.5rem;
  min-height: 2.5rem;
  padding: 0;
  border-radius: 999px;
  flex-shrink: 0;
  cursor: pointer;
  box-sizing: border-box;
}

.chat-embed__attach {
  border: 0;
  background: transparent;
  color: rgba(46, 42, 51, 0.55);
  transition: color 0.15s ease;
}

.chat-embed__attach:hover,
.chat-embed__attach.is-active {
  color: var(--chat-coral);
}

.chat-embed__attach svg,
.chat-embed__send svg {
  display: block;
  width: 1.125rem;
  height: 1.125rem;
}

.chat-embed__send {
  border: 0;
  background: var(--chat-grad);
  color: #fff;
  box-shadow: 0 4px 14px var(--chat-glow);
}

.chat-embed__send:hover {
  filter: brightness(1.06);
}

#send-form input[type="file"] {
  display: none !important;
}

.chat-embed__body--page {
  min-height: 100dvh;
}

.chat-embed__preview-banner {
  padding: 0.5rem 1rem;
  text-align: center;
  font-size: 0.75rem;
  color: rgba(46, 42, 51, 0.65);
  background: rgba(232, 155, 42, 0.12);
  border-bottom: 1px solid rgba(232, 155, 42, 0.2);
}

.chat-embed__page-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid rgba(46, 42, 51, 0.08);
}

.chat-embed__page-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  background: rgba(232, 131, 107, 0.12);
  color: #e8836b;
  font-size: 0.85rem;
}

.chat-embed__page-title {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 700;
}

.chat-embed__page-sub {
  margin: 0;
  font-size: 0.75rem;
  color: rgba(46, 42, 51, 0.5);
}

html.chat-embed--dark .chat-embed__preview-banner {
  color: rgba(237, 232, 227, 0.65);
}

html.chat-embed--dark .chat-embed__page-header {
  border-bottom-color: rgba(255, 255, 255, 0.08);
}

html.chat-embed--dark .chat-embed__page-sub {
  color: rgba(237, 232, 227, 0.45);
}

html.chat-embed--dark,
html.chat-embed--dark body.chat-embed__body {
  background: #1a1714;
  color: #ede8e3;
}

html.chat-embed--dark .chat-embed__messages {
  background: #1a1714;
}

html.chat-embed--dark .chat-msg--bot .chat-msg__bubble,
html.chat-embed--dark .chat-msg--typing .chat-msg__bubble {
  background: #252019;
  border-color: rgba(255, 255, 255, 0.08);
  color: #ede8e3;
}

html.chat-embed--dark .chat-msg--typing .chat-msg__bubble {
  color: rgba(237, 232, 227, 0.45);
}

html.chat-embed--dark .chat-embed__composer {
  background: #252019;
  border-top-color: rgba(255, 255, 255, 0.08);
}

html.chat-embed--dark .chat-embed__input {
  background: #1a1714;
  border-color: rgba(255, 255, 255, 0.12);
  color: #ede8e3;
}

html.chat-embed--dark .chat-embed__attach {
  color: rgba(237, 232, 227, 0.6);
}

html.chat-embed--dark .chat-embed__attach:hover,
html.chat-embed--dark .chat-embed__attach.is-active {
  color: var(--chat-coral);
}

.chat-msg__img {
  display: block;
  max-width: min(100%, 14rem);
  border-radius: 0.75rem;
  margin-bottom: 0.35rem;
}

.chat-msg__table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.5rem 0 0.35rem;
  font-size: 0.82rem;
  table-layout: fixed;
}

.chat-msg__table th,
.chat-msg__table td {
  padding: 0.45rem 0.55rem;
  border: 1px solid rgba(46, 42, 51, 0.12);
  text-align: right;
  vertical-align: top;
  word-break: break-word;
}

.chat-msg__table th {
  font-weight: 700;
  background: rgba(46, 42, 51, 0.06);
}

.chat-msg__table td:nth-child(2) {
  white-space: nowrap;
}

.chat-msg--bot .chat-msg__bubble .chat-msg__table {
  margin-top: 0.65rem;
}

html.chat-embed--dark .chat-msg__table th,
html.chat-embed--dark .chat-msg__table td {
  border-color: rgba(245, 238, 232, 0.14);
}

html.chat-embed--dark .chat-msg__table th {
  background: rgba(245, 238, 232, 0.06);
}
