/* Site Assistant widget — configurable via CSS variables + window.SITE_ASSISTANT */
:root {
  --sa-primary: #0b3fd0;
  --sa-primary-dark: #032063;
  --sa-accent: #34a1e5;
  --sa-text: #10214d;
  --sa-bg: #f3f6ff;
  --sa-border: #dde5fb;
}

#spb-root {
  position: fixed;
  right: 16px;
  bottom: 0;
  z-index: 99999;
  font-family: "DM Sans", -apple-system, Segoe UI, sans-serif;
  color: var(--sa-text);
}

#spb-mascot {
  position: relative;
  width: 132px;
  animation: spb-walkin 0.7s cubic-bezier(0.22, 1, 0.36, 1) both;
}
#spb-mascot.spb-mascot-away { display: none; }
#spb-launch {
  display: block;
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
  width: 100%;
  filter: drop-shadow(0 10px 14px rgba(4, 18, 63, 0.28));
  transition: transform 0.25s ease;
}
#spb-launch:hover { transform: translateY(-4px) scale(1.02); }
#spb-mascot .spb-face { width: 100%; height: auto; display: block; }
#spb-launch .spb-mascot-face {
  transform-origin: 50% 100%;
  animation: spb-breathe 4.5s ease-in-out infinite;
}
#spb-cta {
  position: absolute;
  top: 32px;
  left: 30%;
  transform: translateX(-100%);
  border: none;
  font-family: inherit;
  cursor: pointer;
  background: linear-gradient(180deg, #ffffff 55%, #e9eefb);
  color: var(--sa-text);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 10px;
  border-radius: 12px 12px 4px 12px;
  box-shadow:
    0 1px 2px rgba(4, 18, 63, 0.22),
    0 6px 14px rgba(4, 18, 63, 0.3),
    0 14px 32px rgba(4, 18, 63, 0.22);
  white-space: nowrap;
  max-width: 180px;
  animation: spb-cta-pop 0.4s 1.1s both;
}
#spb-mascot-hide {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 2;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: rgba(5, 31, 102, 0.8);
  color: #fff;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s;
}
#spb-mascot:hover #spb-mascot-hide { opacity: 1; }

@keyframes spb-walkin {
  from { opacity: 0; transform: translateX(60px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes spb-breathe {
  0%, 100% { transform: scaleY(1); }
  50%      { transform: scaleY(1.012); }
}
@keyframes spb-cta-pop {
  from { opacity: 0; transform: translateX(-100%) translateY(6px); }
  to   { opacity: 1; transform: translateX(-100%) translateY(0); }
}

.spb-face { display: block; object-fit: cover; }

#spb-panel {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 372px;
  max-width: calc(100vw - 24px);
  height: 560px;
  max-height: calc(100vh - 40px);
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 12px 48px rgba(4, 18, 63, 0.35);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#spb-panel[hidden] { display: none; }
.spb-head-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: linear-gradient(160deg, var(--sa-primary), var(--sa-primary-dark));
  color: #fff;
}
.spb-head-avatar {
  width: 46px;
  height: 46px;
  flex: none;
  border-radius: 50%;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.15);
}
.spb-head-avatar .spb-face,
.spb-mini .spb-face {
  width: 100%;
  height: 100%;
  margin: 0;
  display: block;
}
/* Face (default): fill circle, head toward top */
#spb-root.sa-crop-face .spb-head-avatar .spb-face,
#spb-root.sa-crop-face .spb-mini .spb-face,
#spb-root:not(.sa-crop-full) .spb-head-avatar .spb-face,
#spb-root:not(.sa-crop-full) .spb-mini .spb-face {
  object-fit: cover;
  object-position: center top;
}
/* Full: whole image visible in circle */
#spb-root.sa-crop-full .spb-head-avatar .spb-face,
#spb-root.sa-crop-full .spb-mini .spb-face {
  object-fit: contain;
  object-position: center center;
}
.spb-titles {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
  min-width: 0;
  flex: 1;
}
.spb-titles strong {
  font-family: Poppins, "DM Sans", sans-serif;
  font-weight: 600;
  font-size: 15px;
}
#spb-status { font-size: 12px; color: #a9c3ff; }
#spb-close {
  margin-left: auto;
  background: none;
  border: none;
  color: #fff;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  opacity: 0.85;
}
#spb-close:hover { opacity: 1; }

#spb-msgs {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
  background: var(--sa-bg);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.spb-msg {
  max-width: 88%;
  font-size: 14px;
  line-height: 1.5;
  color: var(--sa-text);
  word-wrap: break-word;
}
.spb-msg-u {
  align-self: flex-end;
  background: var(--sa-primary);
  color: #fff;
  padding: 9px 13px;
  border-radius: 14px 14px 4px 14px;
}
.spb-msg-a {
  align-self: flex-start;
  display: flex;
  gap: 8px;
}
.spb-mini {
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  overflow: hidden;
  background: #eef2ff;
  align-self: flex-end;
}
.spb-bubble {
  background: #fff;
  border: 1px solid var(--sa-border);
  padding: 9px 13px;
  border-radius: 14px 14px 14px 4px;
}
.spb-bubble p { margin: 0 0 8px; }
.spb-bubble p:last-child,
.spb-bubble ul:last-child,
.spb-bubble table:last-child { margin-bottom: 0; }
.spb-bubble .spb-h {
  font-family: Poppins, "DM Sans", sans-serif;
  font-weight: 600;
}
.spb-bubble a {
  color: var(--sa-primary);
  font-weight: 600;
  text-decoration: underline;
}
.spb-bubble ul { margin: 0 0 8px; padding-left: 18px; }
.spb-bubble table {
  border-collapse: collapse;
  margin: 0 0 8px;
  font-size: 13px;
  width: 100%;
}
.spb-bubble th,
.spb-bubble td {
  border: 1px solid var(--sa-border);
  padding: 4px 7px;
  text-align: left;
}
.spb-bubble th { background: #eef2ff; font-weight: 600; }

.spb-dots i {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 4px;
  border-radius: 50%;
  background: #7f97d9;
  animation: spb-bounce 1.1s infinite;
}
.spb-dots i:nth-child(2) { animation-delay: 0.15s; }
.spb-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes spb-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-5px); }
}

#spb-form {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  background: #fff;
  border-top: 1px solid #e7ecfb;
}
#spb-input {
  flex: 1;
  border: 1px solid #ccd7f6;
  border-radius: 999px;
  padding: 9px 15px;
  font-size: 14px;
  font-family: inherit;
  color: var(--sa-text);
  outline: none;
}
#spb-input:focus {
  border-color: var(--sa-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--sa-accent) 25%, transparent);
}
#spb-send {
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  background: var(--sa-primary);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  flex: none;
}
#spb-send:hover { filter: brightness(0.92); }
#spb-send:disabled { opacity: 0.55; cursor: default; }

.spb-foot {
  text-align: center;
  font-size: 11px;
  color: #8a97bd;
  padding: 5px 10px 8px;
  background: #fff;
}
.spb-lead-toggle {
  display: block;
  width: 100%;
  border: none;
  background: #eef2ff;
  color: var(--sa-primary);
  font-size: 12px;
  font-weight: 600;
  padding: 8px;
  cursor: pointer;
  border-top: 1px solid #e7ecfb;
}
.spb-lead-toggle:hover { background: #e3e9ff; }
#spb-lead {
  padding: 10px 12px;
  background: #fff;
  border-top: 1px solid #e7ecfb;
  display: none;
  flex-direction: column;
  gap: 8px;
}
#spb-lead.open { display: flex; }
#spb-lead input {
  border: 1px solid #ccd7f6;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
}
#spb-lead button[type="submit"] {
  border: none;
  border-radius: 8px;
  background: var(--sa-primary);
  color: #fff;
  font-weight: 600;
  padding: 9px;
  cursor: pointer;
}
#spb-lead-msg { font-size: 12px; color: #5a6a9a; min-height: 1em; }

@media (max-width: 480px) {
  #spb-mascot { width: 78px; }
  #spb-cta {
    font-size: 12px;
    padding: 5px 8px;
    white-space: normal;
    width: 116px;
    text-align: left;
  }
  #spb-panel {
    right: 0;
    bottom: 0;
    width: 100vw;
    max-width: 100vw;
    height: 82vh;
    border-radius: 16px 16px 0 0;
  }
}
