/* ویجت پشتیبانی مصرف‌شاپ — UI شیک / اپ‌پسند */
.ms-sc {
  --ms-sc-brand: #0d7a63;
  --ms-sc-brand-2: #14b8a6;
  --ms-sc-accent: #ff8a2a;
  --ms-sc-ink: #0f172a;
  --ms-sc-muted: #64748b;
  --ms-sc-glass: rgba(255, 255, 255, 0.92);
  --ms-sc-shadow: 0 18px 50px rgba(11, 92, 75, 0.22);
  --ms-sc-lift: calc(var(--app-tabbar-h, 0px) + env(safe-area-inset-bottom, 0px));

  position: fixed;
  z-index: 9990;
  /* سمت شروع اینلاین = راست در RTL → دور از تب «حساب» سمت چپ */
  inset-inline-start: 1.1rem;
  bottom: calc(1.15rem + var(--ms-sc-lift));
  font-family: Vazirmatn, Vazir, Tahoma, sans-serif;
  direction: rtl;
  -webkit-tap-highlight-color: transparent;
  /* Dead-zone pad: circular FAB border-radius clips corner hits to this root */
  cursor: pointer;
}
/* Rectangular hit pad larger than the round FAB (and its pulse ring) */
.ms-sc::after {
  content: "";
  position: absolute;
  inset: -12px;
  border-radius: 1.25rem;
  z-index: 0;
}
.ms-sc-menu,
.ms-sc-panel {
  z-index: 2;
}

.ms-sc-fab {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 3.85rem;
  height: 3.85rem;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  color: #fff;
  background:
    radial-gradient(circle at 28% 22%, rgba(255, 255, 255, 0.35), transparent 42%),
    linear-gradient(145deg, var(--ms-sc-brand-2) 0%, var(--ms-sc-brand) 48%, var(--ms-sc-accent) 130%);
  box-shadow:
    0 14px 32px rgba(11, 92, 75, 0.32),
    0 2px 0 rgba(255, 255, 255, 0.22) inset;
  transition: transform 0.22s cubic-bezier(.2, .9, .2, 1), box-shadow 0.22s ease, filter 0.22s ease;
  touch-action: manipulation;
}
/* Square hit layer inside the circular button — corners stay clickable */
.ms-sc-fab::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 0;
}
.ms-sc-fab::before {
  content: "";
  position: absolute;
  inset: -5px;
  border-radius: inherit;
  border: 1.5px solid rgba(11, 92, 75, 0.22);
  animation: ms-sc-ring 2.4s ease-out infinite;
  pointer-events: none;
  z-index: 0;
}
.ms-sc-fab > * {
  position: relative;
  z-index: 1;
  pointer-events: none;
}
.ms-sc-fab:hover,
.ms-sc-fab:focus-visible {
  transform: translateY(-2px) scale(1.04);
  outline: none;
  box-shadow:
    0 18px 40px rgba(11, 92, 75, 0.38),
    0 2px 0 rgba(255, 255, 255, 0.28) inset;
}
.ms-sc-fab:active { transform: scale(0.97); }
.ms-sc-fab.is-open {
  background: linear-gradient(145deg, #1e293b, #0f172a);
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.35);
}
.ms-sc-fab.is-open::before { display: none; }
.ms-sc-fab svg { width: 22px; height: 22px; }
.ms-sc-badge {
  position: absolute;
  top: -2px;
  inset-inline-end: -2px;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 0.3rem;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  box-shadow: 0 0 0 2px #fff;
  line-height: 1;
}

@keyframes ms-sc-ring {
  0% { transform: scale(0.92); opacity: .7; }
  70% { transform: scale(1.18); opacity: 0; }
  100% { transform: scale(1.18); opacity: 0; }
}

.ms-sc-menu {
  position: absolute;
  bottom: calc(100% + 0.85rem);
  inset-inline-start: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.55rem;
  opacity: 0;
  visibility: hidden;
  transform: translateY(0.55rem) scale(0.98);
  transform-origin: bottom inline-start;
  transition: opacity 0.24s ease, transform 0.24s cubic-bezier(.2, .9, .2, 1), visibility 0.24s;
  pointer-events: none;
  padding: 0.15rem;
}
.ms-sc-menu.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
.ms-sc-menu.is-open .ms-sc-channel {
  animation: ms-sc-pop 0.34s cubic-bezier(.2, .9, .2, 1) both;
}
.ms-sc-menu.is-open .ms-sc-channel:nth-child(1) { animation-delay: 0.02s; }
.ms-sc-menu.is-open .ms-sc-channel:nth-child(2) { animation-delay: 0.06s; }
.ms-sc-menu.is-open .ms-sc-channel:nth-child(3) { animation-delay: 0.1s; }
.ms-sc-menu.is-open .ms-sc-channel:nth-child(4) { animation-delay: 0.14s; }
.ms-sc-menu.is-open .ms-sc-channel:nth-child(5) { animation-delay: 0.18s; }
.ms-sc-menu.is-open .ms-sc-channel:nth-child(6) { animation-delay: 0.22s; }
.ms-sc-menu.is-open .ms-sc-channel:nth-child(7) { animation-delay: 0.26s; }
.ms-sc-menu.is-open .ms-sc-channel:nth-child(8) { animation-delay: 0.3s; }

@keyframes ms-sc-pop {
  from { opacity: 0; transform: translateY(0.4rem) scale(0.94); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.ms-sc-channel {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  text-decoration: none;
  color: inherit;
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
  font: inherit;
  --ms-sc-color: var(--ms-sc-brand);
}
.ms-sc-channel:hover .ms-sc-channel-btn,
.ms-sc-channel:focus-visible .ms-sc-channel-btn {
  transform: translateY(-1px) scale(1.06);
  box-shadow:
    0 12px 26px color-mix(in srgb, var(--ms-sc-color) 42%, transparent),
    0 1px 0 rgba(255, 255, 255, 0.25) inset;
}
.ms-sc-channel:hover .ms-sc-channel-label {
  transform: translateX(-2px);
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.12);
}

.ms-sc-channel-btn {
  width: 3rem;
  height: 3rem;
  border-radius: 999px;
  display: grid;
  place-items: center;
  color: #fff;
  background:
    radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.28), transparent 45%),
    var(--ms-sc-color);
  box-shadow: 0 10px 22px rgba(15, 23, 42, 0.16);
  flex-shrink: 0;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  overflow: hidden;
  position: relative;
}
.ms-sc-channel-logo {
  width: 1.4rem;
  height: 1.4rem;
  object-fit: contain;
  display: block;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.12));
}
.ms-sc-channel-fallback { display: grid; place-items: center; }
.ms-sc-channel-label {
  background: var(--ms-sc-glass);
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 999px;
  padding: 0.48rem 0.95rem;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--ms-sc-ink);
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.1);
  white-space: nowrap;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

/* پنل چت */
.ms-sc-panel {
  position: absolute;
  bottom: calc(100% + 0.85rem);
  inset-inline-start: 0;
  width: min(22.5rem, calc(100vw - 1.75rem));
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  border-radius: 1.35rem;
  border: 1px solid rgba(226, 232, 240, 0.95);
  box-shadow: var(--ms-sc-shadow);
  overflow: hidden;
  display: none;
  transform-origin: bottom inline-start;
}
.ms-sc-panel.is-open {
  display: block;
  animation: ms-sc-panel-in 0.28s cubic-bezier(.2, .9, .2, 1) both;
}
@keyframes ms-sc-panel-in {
  from { opacity: 0; transform: translateY(0.5rem) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.ms-sc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  padding: 1rem 1.05rem;
  background:
    radial-gradient(circle at 85% 0%, rgba(244, 123, 32, 0.35), transparent 40%),
    linear-gradient(135deg, #084539 0%, #0b5c4b 45%, #0f766e 100%);
  color: #fff;
  position: relative;
}
.ms-sc-head::after {
  content: "";
  position: absolute;
  inset-inline: 0;
  bottom: -1px;
  height: 18px;
  background: linear-gradient(180deg, rgba(8, 69, 57, 0.12), transparent);
  pointer-events: none;
}
.ms-sc-head-main {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
}
.ms-sc-avatar {
  width: 2.55rem;
  height: 2.55rem;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.28);
  flex-shrink: 0;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
}
.ms-sc-head h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.25;
}
.ms-sc-status {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.2rem;
  font-size: 0.72rem;
  font-weight: 600;
  opacity: 0.92;
}
.ms-sc-status i {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 999px;
  background: #4ade80;
  box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.28);
  display: inline-block;
}
.ms-sc-close {
  border: none;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  width: 2.15rem;
  height: 2.15rem;
  border-radius: 0.75rem;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.15s ease, transform 0.15s ease;
  flex-shrink: 0;
}
.ms-sc-close:hover { background: rgba(255, 255, 255, 0.24); transform: scale(1.04); }

.ms-sc-body {
  padding: 0.95rem;
  background:
    radial-gradient(circle at 0% 0%, rgba(11, 92, 75, 0.04), transparent 42%),
    #f8fafc;
}
.ms-sc-welcome {
  margin: 0 0 0.85rem;
  font-size: 0.84rem;
  color: var(--ms-sc-muted);
  line-height: 1.7;
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid rgba(226, 232, 240, 0.9);
  border-radius: 0.95rem;
  padding: 0.7rem 0.85rem;
}
.ms-sc-guest-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
  margin-bottom: 0.65rem;
}
.ms-sc-guest-fields input,
.ms-sc-compose textarea {
  width: 100%;
  border: 1px solid #e2e8f0;
  border-radius: 0.85rem;
  padding: 0.6rem 0.75rem;
  font: inherit;
  box-sizing: border-box;
  background: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.ms-sc-guest-fields input:focus,
.ms-sc-compose textarea:focus {
  outline: none;
  border-color: #8ecdbc;
  box-shadow: 0 0 0 3px rgba(11, 92, 75, 0.12);
}
.ms-sc-thread {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: min(16rem, 42vh);
  overflow: auto;
  margin-bottom: 0.7rem;
  padding: 0.35rem 0.15rem;
  scroll-behavior: smooth;
}
.ms-sc-msg { max-width: 86%; }
.ms-sc-msg.is-mine { align-self: flex-start; }
.ms-sc-msg.is-them { align-self: flex-end; }
.ms-sc-msg.is-bot .ms-sc-bubble {
  background: linear-gradient(180deg, #ecfeff, #f0fdfa);
  border-color: #99f6e4;
}
.ms-sc-bubble {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 1rem;
  padding: 0.55rem 0.8rem;
  font-size: 0.86rem;
  line-height: 1.6;
  white-space: pre-wrap;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.04);
}
.ms-sc-msg.is-mine .ms-sc-bubble {
  background: linear-gradient(135deg, #0b5c4b, #0f766e);
  color: #fff;
  border-color: transparent;
  border-bottom-right-radius: 0.35rem;
}
.ms-sc-msg.is-them .ms-sc-bubble,
.ms-sc-msg.is-bot .ms-sc-bubble {
  border-bottom-left-radius: 0.35rem;
}
.ms-sc-meta {
  font-size: 0.68rem;
  color: #94a3b8;
  margin-bottom: 0.18rem;
  font-weight: 600;
}
.ms-sc-compose {
  display: flex;
  gap: 0.45rem;
  align-items: flex-end;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 1rem;
  padding: 0.35rem;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.05);
}
.ms-sc-compose textarea {
  border: 0;
  box-shadow: none;
  resize: none;
  min-height: 2.6rem;
  max-height: 6rem;
  padding: 0.55rem 0.65rem;
  background: transparent;
}
.ms-sc-compose textarea:focus { box-shadow: none; border: 0; }
.ms-sc-send {
  border: none;
  background: linear-gradient(145deg, #0b5c4b, #0f766e);
  color: #fff;
  border-radius: 0.85rem;
  width: 2.7rem;
  height: 2.7rem;
  cursor: pointer;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  box-shadow: 0 8px 18px rgba(11, 92, 75, 0.28);
  transition: transform 0.15s ease, filter 0.15s ease;
}
.ms-sc-send:hover { transform: scale(1.05); }
.ms-sc-send:active { transform: scale(0.96); }

@media (max-width: 860px) {
  .ms-sc {
    inset-inline-start: 0.85rem;
    bottom: calc(0.85rem + var(--ms-sc-lift));
  }
  .ms-sc-panel {
    width: min(22rem, calc(100vw - 1.35rem));
  }
  .ms-sc-channel-label {
    max-width: 11.5rem;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .ms-sc-guest-fields { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .ms-sc-fab { width: 3.55rem; height: 3.55rem; }
  .ms-sc-panel {
    /* روی موبایل پنل را به لبه نزدیک‌تر کن تا برش نخورد */
    width: calc(100vw - 1.1rem);
    max-width: calc(100vw - 1.1rem);
  }
}

/* اپ موبایل: بالاتر از تب‌بار / نوار تسویه، سمت راست (دور از «حساب» در چپ) */
body.app-shell .ms-sc {
  --ms-sc-lift: calc(var(--app-tabbar-h, 64px) + env(safe-area-inset-bottom, 0px));
  bottom: calc(0.85rem + var(--ms-sc-lift));
  inset-inline-start: 0.85rem;
  inset-inline-end: auto;
  /* Above .app-tabbar (60) and .dgk-mobilebar (90) */
  z-index: 100;
}
/* نوار پایین تسویه (سبد / پرداخت) را نپوشاند */
@media (max-width: 860px) {
  body:has(.dgk-mobilebar) .ms-sc {
    bottom: calc(0.75rem + var(--ms-sc-lift, 0px) + 4.6rem) !important;
  }
}
body.app-shell .ms-sc-fab {
  width: 3.35rem;
  height: 3.35rem;
}
