:root {
  --subly-chat-brand: #2b8cff;
  --subly-chat-brand-dark: #1a6fd4;
  --subly-chat-ink: #10162f;
  --subly-chat-muted: #66708a;
  --subly-chat-line: rgba(20, 40, 90, .12);
}

.subly-chat-launcher {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 2147483000;
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 19px;
  color: #fff;
  background: linear-gradient(135deg, #2b8cff 0%, #765bff 62%, #ff7eaf 125%);
  box-shadow: 0 16px 38px rgba(43, 112, 224, .38);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform .18s ease, box-shadow .18s ease;
}

.subly-chat-launcher:hover { transform: translateY(-2px); box-shadow: 0 19px 44px rgba(43, 112, 224, .46); }
.subly-chat-launcher:focus-visible, .subly-chat button:focus-visible, .subly-chat input:focus-visible, .subly-chat textarea:focus-visible { outline: 3px solid rgba(43, 140, 255, .28); outline-offset: 2px; }
.subly-chat-launcher svg { width: 28px; height: 28px; }
.subly-chat-launcher .subly-chat-badge { position: absolute; top: -4px; right: -4px; min-width: 20px; height: 20px; padding: 0 5px; box-sizing: border-box; border-radius: 12px; border: 2px solid #fff; background: #ff4d62; color: #fff; font: 700 11px/16px Inter, system-ui, sans-serif; display: none; place-items: center; }
.subly-chat-launcher .subly-chat-badge.on { display: grid; }

.subly-chat {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: calc(max(20px, env(safe-area-inset-bottom)) + 70px);
  z-index: 2147483001;
  width: min(390px, calc(100vw - 28px));
  height: min(650px, calc(100dvh - 110px));
  border: 1px solid var(--subly-chat-line);
  border-radius: 24px;
  background: #fff;
  color: var(--subly-chat-ink);
  box-shadow: 0 26px 80px rgba(17, 29, 60, .24);
  overflow: hidden;
  display: none;
  grid-template-rows: auto 1fr auto;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  text-align: left;
  transform-origin: right bottom;
}

.subly-chat.open { display: grid; animation: sublyChatIn .22s ease both; }
@keyframes sublyChatIn { from { opacity: 0; transform: translateY(12px) scale(.97); } to { opacity: 1; transform: none; } }

.subly-chat-head { padding: 17px 17px 14px; color: #fff; background: linear-gradient(120deg, #277fde, #735aff 72%, #ec79a8 130%); }
.subly-chat-head-row { display: flex; align-items: center; gap: 11px; }
.subly-chat-logo { width: 40px; height: 40px; flex: 0 0 auto; border-radius: 13px; display: grid; place-items: center; background: rgba(255,255,255,.18); border: 1px solid rgba(255,255,255,.2); font: 800 21px/1 "Plus Jakarta Sans", Inter, sans-serif; }
.subly-chat-title { min-width: 0; flex: 1; }
.subly-chat-title strong { display: block; font: 750 15px/1.2 "Plus Jakarta Sans", Inter, sans-serif; }
.subly-chat-presence { display: flex; align-items: center; gap: 6px; margin-top: 4px; font-size: 11.5px; opacity: .9; }
.subly-chat-dot { width: 7px; height: 7px; border-radius: 50%; background: #73f3b4; box-shadow: 0 0 0 3px rgba(115,243,180,.18); }
.subly-chat-close { width: 34px; height: 34px; border: 0; border-radius: 11px; background: rgba(255,255,255,.14); color: #fff; font-size: 18px; cursor: pointer; }

.subly-chat-body { min-height: 0; overflow-y: auto; padding: 18px 14px 14px; background: linear-gradient(#fbfcff, #fff); scroll-behavior: smooth; }
.subly-chat-welcome { padding: 3px 4px 12px; }
.subly-chat-welcome h3 { margin: 0 0 6px; color: var(--subly-chat-ink); font: 750 18px/1.3 "Plus Jakarta Sans", Inter, sans-serif; }
.subly-chat-welcome p { margin: 0; color: var(--subly-chat-muted); font-size: 13px; line-height: 1.55; }
.subly-chat-chips { display: flex; flex-wrap: wrap; gap: 7px; padding: 2px 2px 14px; }
.subly-chat-chip { border: 1px solid rgba(43,140,255,.2); border-radius: 999px; padding: 8px 10px; background: rgba(43,140,255,.055); color: #236fc0; font: 650 11.5px/1.2 Inter, sans-serif; cursor: pointer; }
.subly-chat-chip:hover { background: rgba(43,140,255,.1); }
.subly-chat-msg { display: flex; margin: 8px 0; }
.subly-chat-msg.visitor { justify-content: flex-end; }
.subly-chat-bubble { max-width: 82%; border-radius: 16px; padding: 10px 12px; font-size: 13px; line-height: 1.48; white-space: pre-wrap; overflow-wrap: anywhere; }
.subly-chat-msg.ai .subly-chat-bubble, .subly-chat-msg.admin .subly-chat-bubble, .subly-chat-msg.system .subly-chat-bubble { background: #f0f4fa; color: #202942; border-bottom-left-radius: 5px; }
.subly-chat-msg.admin .subly-chat-bubble { background: #eef9f4; }
.subly-chat-msg.visitor .subly-chat-bubble { background: var(--subly-chat-brand); color: #fff; border-bottom-right-radius: 5px; }
.subly-chat-meta { display: block; margin-top: 4px; font-size: 9.5px; opacity: .58; }
.subly-chat-typing { display: none; align-items: center; gap: 4px; width: fit-content; margin: 8px 0; padding: 11px 13px; border-radius: 15px 15px 15px 5px; background: #f0f4fa; }
.subly-chat-typing.on { display: flex; }
.subly-chat-typing i { width: 6px; height: 6px; border-radius: 50%; background: #8290aa; animation: sublyDot 1s infinite ease-in-out; }
.subly-chat-typing i:nth-child(2) { animation-delay: .14s; }.subly-chat-typing i:nth-child(3) { animation-delay: .28s; }
@keyframes sublyDot { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-4px); opacity: 1; } }

.subly-chat-handoff { margin: 10px 0; padding: 13px; border: 1px solid rgba(43,140,255,.18); border-radius: 15px; background: #f7faff; }
.subly-chat-handoff strong { display: block; margin-bottom: 4px; font-size: 13px; }
.subly-chat-handoff p { margin: 0 0 10px; color: var(--subly-chat-muted); font-size: 11.5px; line-height: 1.45; }
.subly-chat-form { display: grid; gap: 7px; }
.subly-chat-form input { width: 100%; box-sizing: border-box; border: 1px solid var(--subly-chat-line); border-radius: 10px; padding: 9px 10px; background: #fff; color: var(--subly-chat-ink); font: 12px Inter, sans-serif; }
.subly-chat-primary, .subly-chat-secondary { border: 0; border-radius: 10px; padding: 9px 11px; font: 700 11.5px Inter, sans-serif; cursor: pointer; }
.subly-chat-primary { background: var(--subly-chat-brand); color: #fff; }.subly-chat-primary:hover { background: var(--subly-chat-brand-dark); }
.subly-chat-secondary { background: #edf2f8; color: #42506b; }
.subly-chat-form-error { display: none; color: #c43f4f; font-size: 10.5px; }.subly-chat-form-error.on { display: block; }

.subly-chat-foot { padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--subly-chat-line); background: #fff; }
.subly-chat-status { display: none; align-items: center; justify-content: space-between; gap: 8px; margin: 0 1px 8px; color: #52617d; font-size: 10.5px; }
.subly-chat-status.on { display: flex; }
.subly-chat-status button { border: 0; padding: 0; background: none; color: var(--subly-chat-brand-dark); font: 700 10.5px Inter, sans-serif; cursor: pointer; }
.subly-chat-compose { display: flex; align-items: flex-end; gap: 8px; }
.subly-chat-compose textarea { flex: 1; min-height: 42px; max-height: 96px; resize: none; box-sizing: border-box; border: 1px solid var(--subly-chat-line); border-radius: 13px; padding: 11px 12px; background: #f9fbfe; color: var(--subly-chat-ink); font: 13px/1.4 Inter, sans-serif; }
.subly-chat-compose textarea::placeholder { color: #929bb0; }
.subly-chat-send { width: 42px; height: 42px; flex: 0 0 auto; border: 0; border-radius: 13px; display: grid; place-items: center; background: var(--subly-chat-brand); color: #fff; cursor: pointer; }
.subly-chat-send:disabled { opacity: .48; cursor: default; }.subly-chat-send svg { width: 18px; height: 18px; }
.subly-chat-powered { margin-top: 7px; text-align: center; color: #99a1b2; font-size: 9.5px; }

@media (max-width: 520px) {
  .subly-chat-launcher { right: 14px; bottom: 14px; }
  .subly-chat { inset: 0; width: 100%; height: 100dvh; max-height: none; border: 0; border-radius: 0; }
  .subly-chat-head { padding-top: calc(16px + env(safe-area-inset-top)); }
}

@media (prefers-reduced-motion: reduce) {
  .subly-chat.open, .subly-chat-typing i { animation: none; }
  .subly-chat-launcher { transition: none; }
}
