/* SwiftNest chat widget. Everything is scoped to #swfnChatRoot. */

#swfnChatRoot {
  --swfn-brand: #2550F5;
  --swfn-brand-strong: #1A36C9;
  --swfn-on-brand: #FFFFFF;
  --swfn-bg: #FFFFFF;
  --swfn-bg-2: #F4F6FB;
  --swfn-line: #DDE3EF;
  --swfn-ink: #0B1426;
  --swfn-muted: #5E6A85;
  --swfn-them: #EEF2FA;
  --swfn-ok: #0F9A66;
  --swfn-off: #8C97AE;
  --swfn-bad: #C62F2F;
  --swfn-bad-bg: #FDECEC;
  --swfn-shadow: 0 24px 60px -16px rgba(11, 20, 38, 0.35), 0 2px 8px rgba(11, 20, 38, 0.08);
  font-family: var(--font, 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif);
  color: var(--swfn-ink);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #swfnChatRoot {
    --swfn-brand: #6E8EFF;
    --swfn-brand-strong: #93ABFF;
    --swfn-on-brand: #0A1020;
    --swfn-bg: #121B30;
    --swfn-bg-2: #0E1528;
    --swfn-line: #233050;
    --swfn-ink: #EEF2FA;
    --swfn-muted: #8F9AB5;
    --swfn-them: #1B2742;
    --swfn-ok: #3DD69B;
    --swfn-off: #6B7794;
    --swfn-bad: #FF8A8A;
    --swfn-bad-bg: rgba(255, 122, 122, 0.12);
    --swfn-shadow: 0 24px 60px -16px rgba(0, 0, 0, 0.75), 0 2px 8px rgba(0, 0, 0, 0.4);
  }
}

:root[data-theme="dark"] #swfnChatRoot {
  --swfn-brand: #6E8EFF;
  --swfn-brand-strong: #93ABFF;
  --swfn-on-brand: #0A1020;
  --swfn-bg: #121B30;
  --swfn-bg-2: #0E1528;
  --swfn-line: #233050;
  --swfn-ink: #EEF2FA;
  --swfn-muted: #8F9AB5;
  --swfn-them: #1B2742;
  --swfn-ok: #3DD69B;
  --swfn-off: #6B7794;
  --swfn-bad: #FF8A8A;
  --swfn-bad-bg: rgba(255, 122, 122, 0.12);
  --swfn-shadow: 0 24px 60px -16px rgba(0, 0, 0, 0.75), 0 2px 8px rgba(0, 0, 0, 0.4);
}

#swfnChatRoot *,
#swfnChatRoot *::before,
#swfnChatRoot *::after {
  box-sizing: border-box;
}

#swfnChatRoot [hidden] {
  display: none !important;
}

#swfnChatRoot svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#swfnChatRoot button {
  font: inherit;
  cursor: pointer;
}

#swfnChatRoot :focus-visible:not(input):not(textarea) {
  outline: 2px solid var(--swfn-brand);
  outline-offset: 2px;
}

/* ---------- Launcher ---------- */

.swfn-launcher {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 2147483001;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  height: 54px;
  padding: 0 1.25rem 0 1.05rem;
  border: 0;
  border-radius: 999px;
  background: #2550F5;
  color: #FFFFFF;
  font-weight: 700 !important;
  font-size: 15px !important;
  box-shadow: 0 14px 34px -10px rgba(37, 80, 245, 0.65), 0 2px 6px rgba(11, 20, 38, 0.2);
  transition: transform 0.15s ease, background-color 0.15s ease;
}

.swfn-launcher:hover {
  background: #1A36C9;
  transform: translateY(-1px);
}

.swfn-launcher svg {
  width: 22px !important;
  height: 22px !important;
}

.swfn-launcher-icon,
.swfn-launcher-close {
  display: inline-flex;
}

.swfn-launcher-close,
.swfn-launcher[data-open="true"] .swfn-launcher-icon,
.swfn-launcher[data-open="true"] .swfn-launcher-text {
  display: none;
}

.swfn-launcher[data-open="true"] {
  width: 54px;
  padding: 0;
  justify-content: center;
}

.swfn-launcher[data-open="true"] .swfn-launcher-close {
  display: inline-flex;
}

.swfn-badge {
  position: absolute;
  top: -5px;
  right: -3px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 2px solid #FFFFFF;
  background: #FF6B4A;
  color: #FFFFFF;
  font-size: 12px;
  font-weight: 800;
}

/* ---------- Panel ---------- */

.swfn-panel {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: calc(max(18px, env(safe-area-inset-bottom)) + 66px);
  z-index: 2147483000;
  display: flex;
  flex-direction: column;
  width: min(380px, calc(100vw - 36px));
  height: min(600px, calc(100vh - 120px));
  height: min(600px, calc(100dvh - 120px));
  overflow: hidden;
  border: 1px solid var(--swfn-line);
  border-radius: 18px;
  background: var(--swfn-bg);
  box-shadow: var(--swfn-shadow);
  font-size: 15px;
  line-height: 1.45;
  animation: swfn-in 0.18s ease-out;
}

@keyframes swfn-in {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}

.swfn-head {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.9rem 0.75rem 0.9rem 1rem;
  background: #0A1020;
  color: #EEF2FA;
}

.swfn-avatar {
  position: relative;
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #2550F5;
  color: #FFFFFF;
  font-weight: 800;
  font-size: 18px;
}

.swfn-presence {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 2.5px solid #0A1020;
  background: #8C97AE;
}

.swfn-panel[data-status="online"] .swfn-presence {
  background: #3DD69B;
}

.swfn-head-text {
  flex: 1 1 auto;
  min-width: 0;
}

.swfn-title {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
  line-height: 1.25;
  color: inherit;
}

.swfn-sub {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: #9AA6C2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.swfn-icon-btn {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: inherit;
  opacity: 0.85;
}

.swfn-icon-btn:hover {
  opacity: 1;
  background: rgba(127, 140, 170, 0.16);
}

.swfn-sound .swfn-mute,
.swfn-sound[aria-pressed="false"] .swfn-wave {
  display: none;
}

.swfn-sound[aria-pressed="false"] .swfn-mute {
  display: inline;
}

/* ---------- Conversation ---------- */

.swfn-log {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 1rem;
  background: var(--swfn-bg-2);
}

.swfn-msg {
  max-width: 85%;
  padding: 0.6rem 0.85rem;
  border-radius: 16px;
  overflow-wrap: anywhere;
}

.swfn-msg[data-who="admin"] {
  align-self: flex-start;
  background: var(--swfn-them);
  color: var(--swfn-ink);
  border-bottom-left-radius: 5px;
}

.swfn-msg[data-who="visitor"] {
  align-self: flex-end;
  background: var(--swfn-brand);
  color: var(--swfn-on-brand);
  border-bottom-right-radius: 5px;
}

.swfn-msg[data-who="system"] {
  align-self: center;
  max-width: 92%;
  padding: 0.35rem 0.7rem;
  background: transparent;
  color: var(--swfn-muted);
  font-size: 13px;
  text-align: center;
}

.swfn-welcome {
  background: var(--swfn-bg) !important;
  border: 1px solid var(--swfn-line);
}

.swfn-text {
  white-space: pre-wrap;
}

.swfn-msg a {
  color: inherit;
  text-decoration: underline;
}

.swfn-meta {
  display: block;
  margin-top: 0.25rem;
  font-size: 11px;
  opacity: 0.7;
}

.swfn-msg[data-who="visitor"] .swfn-meta {
  text-align: right;
}

.swfn-shot {
  display: block;
  margin-top: 0.4rem;
}

.swfn-shot img {
  display: block;
  max-width: 100%;
  max-height: 180px;
  border-radius: 10px;
}

.swfn-note {
  display: block;
  margin-top: 0.3rem;
  font-size: 13px;
  font-style: italic;
}

.swfn-mailto {
  display: inline-block;
  margin-top: 0.6rem;
  padding: 0.5rem 0.85rem;
  border-radius: 10px;
  background: var(--swfn-brand);
  color: var(--swfn-on-brand) !important;
  font-weight: 700;
  text-decoration: none !important;
}

.swfn-starters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.15rem;
}

.swfn-chip {
  padding: 0.45rem 0.8rem;
  border: 1px solid var(--swfn-line);
  border-radius: 999px;
  background: var(--swfn-bg);
  color: var(--swfn-brand);
  font-size: 13.5px !important;
  font-weight: 650;
}

.swfn-chip:hover {
  border-color: var(--swfn-brand);
}

/* ---------- Composer ---------- */

.swfn-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem 0.85rem 0.6rem;
  border-top: 1px solid var(--swfn-line);
  background: var(--swfn-bg);
}

.swfn-details {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 0.5rem;
}

.swfn-details label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 12px;
  font-weight: 650;
  color: var(--swfn-muted);
}

.swfn-field,
.swfn-input {
  width: 100%;
  border: 1px solid var(--swfn-line);
  border-radius: 10px;
  background: var(--swfn-bg-2);
  color: var(--swfn-ink);
  font: inherit;
  font-size: 16px;
}

.swfn-field {
  padding: 0.45rem 0.6rem;
  font-size: 15px;
}

.swfn-field:focus,
.swfn-input:focus {
  outline: none;
  border-color: var(--swfn-brand);
}

.swfn-link {
  align-self: flex-start;
  max-width: 100%;
  padding: 0;
  border: 0;
  background: none;
  color: var(--swfn-brand);
  font-size: 13px !important;
  font-weight: 650;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.swfn-link:hover {
  text-decoration: underline;
}

.swfn-composer {
  display: flex;
  align-items: flex-end;
  gap: 0.35rem;
}

.swfn-composer .swfn-icon-btn {
  color: var(--swfn-muted);
}

.swfn-input {
  flex: 1 1 auto;
  min-height: 42px;
  max-height: 140px;
  padding: 0.55rem 0.75rem;
  resize: none;
  line-height: 1.4;
}

.swfn-send {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: var(--swfn-brand);
  color: var(--swfn-on-brand);
}

.swfn-send:hover {
  background: var(--swfn-brand-strong);
}

.swfn-send:disabled {
  opacity: 0.55;
  cursor: progress;
}

.swfn-preview {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.35rem 0.4rem 0.35rem 0.35rem;
  border: 1px solid var(--swfn-line);
  border-radius: 10px;
  font-size: 13px;
  color: var(--swfn-muted);
}

.swfn-preview img {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 7px;
}

.swfn-preview span {
  flex: 1 1 auto;
}

.swfn-small {
  width: 30px;
  height: 30px;
}

.swfn-small svg {
  width: 16px;
  height: 16px;
}

.swfn-error {
  margin: 0;
  padding: 0.45rem 0.65rem;
  border-radius: 8px;
  background: var(--swfn-bad-bg);
  color: var(--swfn-bad);
  font-size: 13px;
  font-weight: 600;
}

.swfn-foot {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 11.5px;
  color: var(--swfn-muted);
}

.swfn-counter {
  white-space: nowrap;
}

.swfn-hp {
  position: absolute !important;
  left: -10000px !important;
  width: 1px !important;
  height: 1px !important;
  opacity: 0 !important;
}

/* ---------- Phones: full screen ---------- */

@media (max-width: 520px) {
  .swfn-panel {
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .swfn-head {
    padding-top: max(0.9rem, env(safe-area-inset-top));
  }

  .swfn-launcher[data-open="true"] {
    display: none;
  }

  .swfn-launcher-text {
    display: none;
  }

  .swfn-launcher {
    width: 56px;
    height: 56px;
    padding: 0;
    justify-content: center;
  }

  .swfn-details {
    grid-template-columns: 1fr;
  }

  html.swfn-chat-open,
  html.swfn-chat-open body {
    overflow: hidden;
  }
}

@media (prefers-reduced-motion: reduce) {
  .swfn-panel {
    animation: none;
  }

  .swfn-launcher {
    transition: none;
  }
}
