/* Live support chat widget (visitor side). Everything is scoped under .sc-root. */
.sc-root {
  --sc-accent: var(--accent, #4f46e5);
  --sc-accent-2: var(--accent-2, #0ea5e9);
  --sc-grad: linear-gradient(135deg, var(--sc-accent) 0%, #6366f1 45%, var(--sc-accent-2) 100%);
  --sc-bg: #f6f7fc;
  --sc-text: #0f172a;
  --sc-muted: #64748b;
  --sc-spring: cubic-bezier(.2, .9, .3, 1.15);
  --sc-ease: cubic-bezier(.22, .8, .3, 1);
  position: fixed; right: 20px; bottom: 20px; z-index: 9990;
  font-family: var(--font-body, "Hind Siliguri", system-ui, sans-serif);
  color: var(--sc-text); line-height: 1.45;
}
.sc-root *, .sc-root *::before, .sc-root *::after { box-sizing: border-box; }
.sc-root[hidden] { display: none; }

/* ---------- launcher ---------- */
.sc-launcher {
  position: relative; width: 60px; height: 60px; border: 0; padding: 0; border-radius: 50%;
  background: var(--sc-grad); color: #fff; cursor: pointer; display: grid; place-items: center;
  box-shadow: 0 10px 28px rgba(79, 70, 229, .42), 0 2px 6px rgba(15, 23, 42, .18);
  transition: transform .35s var(--sc-spring), box-shadow .25s ease;
  animation: sc-launcher-in .7s var(--sc-spring) .6s both;
  -webkit-tap-highlight-color: transparent;
}
.sc-launcher:hover { transform: translateY(-3px) scale(1.06); box-shadow: 0 16px 34px rgba(79, 70, 229, .5), 0 3px 8px rgba(15, 23, 42, .2); }
.sc-launcher:active { transform: scale(.94); }
.sc-launcher:focus-visible { outline: 3px solid rgba(14, 165, 233, .6); outline-offset: 3px; }
.sc-launcher .sc-ic { position: absolute; inset: 0; display: grid; place-items: center; transition: transform .45s var(--sc-spring), opacity .25s ease; }
.sc-launcher .sc-ic svg { width: 28px; height: 28px; }
.sc-launcher .sc-ic-x { opacity: 0; transform: rotate(-90deg) scale(.4); }
.sc-root.is-open .sc-launcher .sc-ic-chat { opacity: 0; transform: rotate(90deg) scale(.4); }
.sc-root.is-open .sc-launcher .sc-ic-x { opacity: 1; transform: rotate(0) scale(1); }
.sc-ring {
  position: absolute; inset: 0; border-radius: 50%; pointer-events: none;
  box-shadow: 0 0 0 0 rgba(99, 102, 241, .55);
}
.sc-root.has-unread:not(.is-open) .sc-ring { animation: sc-ring 1.8s ease-out infinite; }
.sc-badge {
  position: absolute; top: -4px; right: -4px; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px;
  background: #ef4444; color: #fff; font: 700 12px/22px var(--font-body, system-ui, sans-serif); text-align: center;
  border: 2px solid #fff; transform: scale(0); transition: transform .4s var(--sc-spring);
}
.sc-root.has-unread:not(.is-open) .sc-badge { transform: scale(1); }
.sc-badge.pop { animation: sc-pop .45s var(--sc-spring); }

/* ---------- panel ---------- */
.sc-panel {
  position: absolute; right: 0; bottom: 76px; width: 380px; height: min(600px, calc(100dvh - 120px));
  display: flex; flex-direction: column; overflow: hidden; border-radius: 22px; background: var(--sc-bg);
  box-shadow: 0 30px 70px rgba(30, 41, 59, .28), 0 6px 18px rgba(30, 41, 59, .12), 0 0 0 1px rgba(15, 23, 42, .06);
  transform-origin: bottom right; opacity: 0; visibility: hidden; pointer-events: none;
  transform: translateY(18px) scale(.86);
  transition: transform .5s var(--sc-spring), opacity .25s ease, visibility 0s linear .5s;
}
.sc-root.is-open .sc-panel { opacity: 1; visibility: visible; pointer-events: auto; transform: none; transition-delay: 0s; }

.sc-head {
  position: relative; flex: none; padding: 16px 16px 18px; color: #fff; background: var(--sc-grad); overflow: hidden;
  display: flex; align-items: center; gap: 12px;
}
.sc-head::before, .sc-head::after { content: ""; position: absolute; border-radius: 50%; background: rgba(255, 255, 255, .13); pointer-events: none; }
.sc-head::before { width: 150px; height: 150px; right: -40px; top: -70px; animation: sc-float 9s ease-in-out infinite; }
.sc-head::after { width: 90px; height: 90px; left: 30%; bottom: -60px; animation: sc-float 11s ease-in-out infinite reverse; }
.sc-avatar {
  position: relative; flex: none; width: 44px; height: 44px; border-radius: 50%; background: rgba(255, 255, 255, .22);
  display: grid; place-items: center; backdrop-filter: blur(6px);
}
.sc-avatar svg { width: 24px; height: 24px; }
.sc-avatar i {
  position: absolute; right: 0; bottom: 0; width: 12px; height: 12px; border-radius: 50%; background: #94a3b8;
  border: 2px solid #5b5ee8; transition: background .3s ease;
}
.sc-root.is-online .sc-avatar i { background: #4ade80; animation: sc-online 2.4s ease-in-out infinite; }
.sc-title { position: relative; flex: 1; min-width: 0; }
.sc-title b { display: block; font: 700 17px/1.2 var(--font-display, var(--font-body, system-ui)); }
.sc-title small { display: block; margin-top: 2px; font-size: 12.5px; opacity: .92; transition: opacity .2s ease; }
.sc-close {
  position: relative; flex: none; width: 34px; height: 34px; border: 0; border-radius: 50%; cursor: pointer;
  background: rgba(255, 255, 255, .16); color: #fff; display: grid; place-items: center; transition: background .2s ease, transform .3s var(--sc-spring);
}
.sc-close:hover { background: rgba(255, 255, 255, .3); transform: rotate(90deg); }
.sc-close svg { width: 18px; height: 18px; }

.sc-conn {
  flex: none; max-height: 0; overflow: hidden; background: #fef3c7; color: #92400e; font-size: 12.5px; text-align: center;
  transition: max-height .3s var(--sc-ease), padding .3s var(--sc-ease);
}
.sc-root.is-offline .sc-conn { max-height: 40px; padding: 6px 10px; }

.sc-body { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.sc-msgs {
  flex: 1; overflow-y: auto; padding: 16px 14px 8px; display: flex; flex-direction: column; gap: 4px;
  overscroll-behavior: contain; scroll-behavior: smooth;
}
.sc-msgs::-webkit-scrollbar { width: 6px; }
.sc-msgs::-webkit-scrollbar-thumb { background: rgba(100, 116, 139, .3); border-radius: 3px; }

.sc-day { align-self: center; margin: 10px 0 6px; padding: 2px 12px; border-radius: 999px; background: rgba(100, 116, 139, .13); color: var(--sc-muted); font-size: 11.5px; font-weight: 600; }
.sc-sys { align-self: center; margin: 8px 0; padding: 4px 12px; border-radius: 999px; background: rgba(79, 70, 229, .08); color: var(--sc-accent); font-size: 12px; text-align: center; animation: sc-in-up .4s var(--sc-spring) both; }

.sc-row { display: flex; max-width: 100%; animation: sc-in-up .42s var(--sc-spring) both; }
.sc-row.me { justify-content: flex-end; }
.sc-row.gap { margin-top: 8px; }
.sc-bubble {
  position: relative; max-width: 82%; padding: 9px 13px 7px; border-radius: 18px; font-size: 15px;
  white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word;
}
.sc-row.them .sc-bubble { background: #fff; border-bottom-left-radius: 6px; box-shadow: 0 1px 2px rgba(15, 23, 42, .08), 0 0 0 1px rgba(15, 23, 42, .04); transform-origin: bottom left; }
.sc-row.me .sc-bubble { background: var(--sc-grad); color: #fff; border-bottom-right-radius: 6px; box-shadow: 0 4px 12px rgba(79, 70, 229, .25); transform-origin: bottom right; }
.sc-row.me.sending .sc-bubble { opacity: .72; }
.sc-row.me.failed .sc-bubble { background: #fee2e2; color: #991b1b; box-shadow: 0 0 0 1px #fca5a5; }
.sc-meta { display: flex; align-items: center; justify-content: flex-end; gap: 4px; margin-top: 2px; font-size: 10.5px; opacity: .65; user-select: none; }
.sc-tick { display: inline-flex; width: 16px; height: 11px; transition: color .3s ease, opacity .3s ease; }
.sc-tick svg { width: 100%; height: 100%; }
.sc-row.me .sc-tick { color: rgba(255, 255, 255, .8); }
.sc-row.me.seen .sc-tick { color: #a5f3fc; opacity: 1; }
.sc-row.me.sending .sc-tick { animation: sc-blink 1s ease-in-out infinite; }
.sc-retry { margin-left: 6px; border: 0; background: none; color: inherit; text-decoration: underline; font: inherit; cursor: pointer; padding: 0; }

.sc-typing {
  flex: none; height: 0; opacity: 0; overflow: hidden; padding: 0 14px; display: flex; align-items: center; gap: 8px;
  color: var(--sc-muted); font-size: 12px; transition: height .25s var(--sc-ease), opacity .25s ease;
}
.sc-typing.on { height: 30px; opacity: 1; }
.sc-dots { display: inline-flex; gap: 3px; padding: 7px 10px; background: #fff; border-radius: 14px; box-shadow: 0 1px 2px rgba(15, 23, 42, .08); }
.sc-dots i { width: 6px; height: 6px; border-radius: 50%; background: #94a3b8; animation: sc-bounce 1.2s ease-in-out infinite; }
.sc-dots i:nth-child(2) { animation-delay: .15s; }
.sc-dots i:nth-child(3) { animation-delay: .3s; }

.sc-form {
  flex: none; display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px 12px; background: #fff;
  border-top: 1px solid rgba(15, 23, 42, .07);
}
.sc-input {
  flex: 1; min-height: 42px; max-height: 120px; resize: none; border: 1.5px solid #e2e8f0; border-radius: 21px;
  padding: 10px 16px; font: inherit; font-size: 15px; color: var(--sc-text); background: #f8fafc; outline: none;
  transition: border-color .2s ease, background .2s ease, box-shadow .2s ease;
}
.sc-panel.locked .sc-form { display: none; }
.sc-input::placeholder { color: #94a3b8; }
.sc-input:focus { border-color: var(--sc-accent); background: #fff; box-shadow: 0 0 0 4px rgba(79, 70, 229, .12); }
.sc-send {
  flex: none; width: 42px; height: 42px; border: 0; border-radius: 50%; cursor: pointer; color: #fff; background: var(--sc-grad);
  display: grid; place-items: center; transition: transform .3s var(--sc-spring), opacity .2s ease, filter .2s ease;
  box-shadow: 0 4px 12px rgba(79, 70, 229, .35);
}
.sc-send svg { width: 20px; height: 20px; transform: translateX(1px); transition: transform .3s var(--sc-spring); }
.sc-send:hover:not(:disabled) { transform: scale(1.1); }
.sc-send:hover:not(:disabled) svg { transform: translateX(3px) translateY(-1px); }
.sc-send:active:not(:disabled) { transform: scale(.9); }
.sc-send:disabled { opacity: .4; cursor: default; filter: grayscale(.4); box-shadow: none; }
.sc-send:focus-visible, .sc-close:focus-visible, .sc-input:focus-visible { outline: 2px solid var(--sc-accent-2); outline-offset: 2px; }

/* ---------- pre-chat (guests) ---------- */
.sc-pre {
  position: absolute; inset: 0; z-index: 3; display: flex; flex-direction: column; justify-content: center; gap: 12px;
  padding: 26px 24px; background: var(--sc-bg); transition: opacity .35s ease, transform .45s var(--sc-ease), visibility 0s linear .45s;
}
.sc-pre.gone { opacity: 0; transform: translateY(-16px); visibility: hidden; pointer-events: none; }
.sc-pre h3 { margin: 0; font: 700 20px/1.25 var(--font-display, var(--font-body, system-ui)); }
.sc-pre p { margin: 0 0 4px; color: var(--sc-muted); font-size: 14px; }
.sc-field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: #334155; }
.sc-field input {
  border: 1.5px solid #e2e8f0; border-radius: 12px; padding: 11px 14px; font: inherit; font-size: 15px; font-weight: 400;
  background: #fff; outline: none; color: var(--sc-text); transition: border-color .2s ease, box-shadow .2s ease;
}
.sc-field input:focus { border-color: var(--sc-accent); box-shadow: 0 0 0 4px rgba(79, 70, 229, .12); }
.sc-field em { font-style: normal; font-weight: 400; color: #94a3b8; }
.sc-start {
  margin-top: 4px; border: 0; border-radius: 12px; padding: 12px 16px; font: 700 15px var(--font-body, system-ui); color: #fff; cursor: pointer;
  background: var(--sc-grad); box-shadow: 0 8px 20px rgba(79, 70, 229, .32); transition: transform .3s var(--sc-spring), box-shadow .2s ease;
}
.sc-start:hover { transform: translateY(-2px); box-shadow: 0 12px 26px rgba(79, 70, 229, .4); }
.sc-start:active { transform: scale(.97); }
.sc-pre-err { min-height: 1em; margin: 0; color: #be123c; font-size: 12.5px; }
.sc-shake { animation: sc-shake .4s ease; }

/* ---------- keyframes ---------- */
@keyframes sc-launcher-in { from { opacity: 0; transform: translateY(24px) scale(.4); } to { opacity: 1; transform: none; } }
@keyframes sc-in-up { from { opacity: 0; transform: translateY(12px) scale(.94); } to { opacity: 1; transform: none; } }
@keyframes sc-pop { 0% { transform: scale(1); } 40% { transform: scale(1.5); } 100% { transform: scale(1); } }
@keyframes sc-ring { 0% { box-shadow: 0 0 0 0 rgba(99, 102, 241, .55); } 100% { box-shadow: 0 0 0 22px rgba(99, 102, 241, 0); } }
@keyframes sc-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-5px); opacity: 1; } }
@keyframes sc-float { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(-14px, 10px); } }
@keyframes sc-online { 0%, 100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, .6); } 50% { box-shadow: 0 0 0 5px rgba(74, 222, 128, 0); } }
@keyframes sc-blink { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }
@keyframes sc-shake { 0%, 100% { transform: none; } 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

/* ---------- small screens: full-screen sheet ---------- */
@media (max-width: 520px) {
  .sc-root { right: 14px; bottom: 14px; }
  .sc-panel {
    position: fixed; inset: 0; width: 100%; height: 100dvh; border-radius: 0; bottom: 0; transform-origin: bottom center;
    transform: translateY(40px) scale(.98);
  }
  .sc-root.is-open .sc-launcher { opacity: 0; pointer-events: none; transform: scale(.5); }
  .sc-head { padding-top: max(16px, env(safe-area-inset-top)); }
  .sc-form { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  .sc-root *, .sc-root *::before, .sc-root *::after { animation-duration: .001s !important; animation-iteration-count: 1 !important; transition-duration: .001s !important; scroll-behavior: auto !important; }
}

/* AI support: who wrote the reply */
.sc-who { font-size: 11px; font-weight: 700; color: #64748b; margin: 0 0 2px; letter-spacing: .01em; }
.sc-who.ai { color: var(--sc-accent, #4f46e5); }
