.sg-chat {
  --sg-chat-ink: #0b1220;
  --sg-chat-text: #404b63;
  --sg-chat-muted: #647086;
  --sg-chat-line: #d2d8e4;
  --sg-chat-soft-line: #e5e8ef;
  --sg-chat-bg: #f7f8fa;
  --sg-chat-surface: #ffffff;
  --sg-chat-accent: #0e7c7b;
  --sg-chat-accent-dark: #0c5e5d;
  color: var(--sg-chat-text);
  font: 400 15px/1.5 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  position: relative;
  z-index: 900;
}

.sg-chat *,
.sg-chat *::before,
.sg-chat *::after {
  box-sizing: border-box;
}

.sg-chat__launcher {
  position: fixed;
  right: 22px;
  bottom: calc(62px + env(safe-area-inset-bottom));
  z-index: 900;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 50px;
  padding: 8px 17px 8px 9px;
  border: 1px solid rgba(11, 18, 32, 0.14);
  border-radius: 999px;
  background: var(--sg-chat-ink);
  color: #fff;
  box-shadow: 0 14px 36px rgba(11, 18, 32, 0.2);
  cursor: pointer;
  font: 700 14px/1 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: -0.01em;
  transition: transform 160ms ease, background 160ms ease, box-shadow 160ms ease, opacity 160ms ease;
}

.sg-chat__launcher:hover {
  background: #151f32;
  box-shadow: 0 17px 42px rgba(11, 18, 32, 0.25);
  transform: translateY(-2px);
}

.sg-chat__launcher:focus-visible,
.sg-chat :where(button, a):focus-visible {
  outline: 3px solid var(--sg-chat-accent-dark);
  outline-offset: 3px;
}

.sg-chat__launcher-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 50%;
  background: #fff;
}

.sg-chat__launcher-mark img {
  display: block;
  width: 28px;
  height: 28px;
}

.sg-chat__launcher-label {
  white-space: nowrap;
}

.sg-chat--open .sg-chat__launcher,
.sg-chat--consent-open .sg-chat__launcher,
body.menu-open .sg-chat__launcher {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(10px);
}

@media (max-width: 1119px) {
  body.mobile-cta-visible:not(.menu-open) .sg-chat__launcher {
    bottom: calc(78px + env(safe-area-inset-bottom));
  }
}

.sg-chat__dialog {
  position: fixed;
  inset: auto 22px calc(122px + env(safe-area-inset-bottom)) auto;
  width: min(410px, calc(100vw - 32px));
  height: min(650px, calc(100dvh - 154px));
  max-height: 650px;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--sg-chat-line);
  border-radius: 12px;
  background: var(--sg-chat-surface);
  color: var(--sg-chat-text);
  box-shadow: 0 24px 70px rgba(11, 18, 32, 0.23);
}

.sg-chat__dialog[open] {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  animation: sg-chat-in 180ms ease-out both;
}

.sg-chat__dialog::backdrop {
  background: rgba(11, 18, 32, 0.42);
  backdrop-filter: blur(2px);
}

@keyframes sg-chat-in {
  from { opacity: 0; transform: translateY(12px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.sg-chat__header {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 68px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--sg-chat-soft-line);
  background: var(--sg-chat-bg);
}

.sg-chat__avatar {
  display: grid;
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid var(--sg-chat-line);
  border-radius: 50%;
  background: #fff;
}

.sg-chat__avatar img {
  display: block;
  width: 31px;
  height: 31px;
}

.sg-chat__identity {
  min-width: 0;
  flex: 1;
}

.sg-chat__title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sg-chat__title {
  margin: 0;
  color: var(--sg-chat-ink);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.sg-chat__badge {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 2px 6px;
  border: 1px solid rgba(14, 124, 123, 0.25);
  border-radius: 999px;
  background: rgba(14, 124, 123, 0.08);
  color: var(--sg-chat-accent-dark);
  font: 600 10px/1.2 "Spline Sans Mono", ui-monospace, monospace;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sg-chat__presence {
  margin: 2px 0 0;
  color: var(--sg-chat-muted);
  font-size: 12px;
}

.sg-chat__close {
  display: grid;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  place-items: center;
  padding: 0;
  border: 1px solid var(--sg-chat-line);
  border-radius: 50%;
  background: #fff;
  color: var(--sg-chat-ink);
  cursor: pointer;
  font: 400 25px/1 sans-serif;
}

.sg-chat__log {
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 14px 14px;
  background:
    linear-gradient(rgba(210, 216, 228, 0.28) 1px, transparent 1px),
    linear-gradient(90deg, rgba(210, 216, 228, 0.28) 1px, transparent 1px),
    var(--sg-chat-bg);
  background-size: 32px 32px;
  scrollbar-color: #b7c0cf transparent;
  scrollbar-width: thin;
}

.sg-chat__message {
  display: flex;
  margin: 0 0 12px;
}

.sg-chat__message--user {
  justify-content: flex-end;
}

.sg-chat__bubble {
  width: fit-content;
  max-width: 88%;
  padding: 10px 12px;
  border: 1px solid var(--sg-chat-line);
  border-radius: 4px 12px 12px 12px;
  background: #fff;
  color: var(--sg-chat-text);
  box-shadow: 0 4px 12px rgba(11, 18, 32, 0.05);
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.sg-chat__message--user .sg-chat__bubble {
  border-color: var(--sg-chat-accent);
  border-radius: 12px 4px 12px 12px;
  background: var(--sg-chat-accent);
  color: #fff;
}

.sg-chat__bubble--thinking {
  min-width: 54px;
  color: var(--sg-chat-muted);
}

.sg-chat__bubble--rich {
  width: 100%;
  max-width: 94%;
  padding: 14px;
  white-space: normal;
}

.sg-chat__answer-lead,
.sg-chat__answer-note,
.sg-chat__answer-question {
  margin: 0;
}

.sg-chat__answer-lead {
  color: var(--sg-chat-ink);
  font-size: 15.5px;
  line-height: 1.42;
}

.sg-chat__answer-points {
  display: grid;
  gap: 6px;
  margin: 10px 0 0;
  padding-left: 20px;
}

.sg-chat__answer-points li::marker {
  color: var(--sg-chat-accent);
}

.sg-chat__answer-note {
  margin-top: 10px;
}

.sg-chat__answer-action {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  margin-top: 12px;
  padding: 8px 12px;
  border: 1px solid rgba(14, 124, 123, 0.36);
  border-radius: 7px;
  background: rgba(14, 124, 123, 0.07);
  color: var(--sg-chat-accent-dark);
  font-weight: 700;
  line-height: 1.3;
  text-decoration: none;
  transition: border-color 140ms ease, background 140ms ease;
}

.sg-chat__answer-action:hover {
  border-color: var(--sg-chat-accent);
  background: rgba(14, 124, 123, 0.12);
}

.sg-chat__answer-question {
  margin-top: 12px;
  color: var(--sg-chat-ink);
}

.sg-chat__dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 12px;
}

.sg-chat__dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--sg-chat-accent);
  animation: sg-chat-dot 1.1s ease-in-out infinite;
}

.sg-chat__dots span:nth-child(2) { animation-delay: 120ms; }
.sg-chat__dots span:nth-child(3) { animation-delay: 240ms; }

@keyframes sg-chat-dot {
  0%, 70%, 100% { opacity: 0.3; transform: translateY(0); }
  35% { opacity: 1; transform: translateY(-3px); }
}

.sg-chat__suggestions {
  display: grid;
  gap: 7px;
  margin: 4px 0 16px;
}

.sg-chat__suggestion {
  width: 100%;
  min-height: 44px;
  padding: 8px 11px;
  border: 1px solid var(--sg-chat-line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--sg-chat-ink);
  cursor: pointer;
  font: 600 13px/1.35 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  text-align: left;
  transition: border-color 140ms ease, background 140ms ease;
}

.sg-chat__suggestion::before {
  content: "→";
  margin-right: 8px;
  color: var(--sg-chat-accent);
}

.sg-chat__suggestion:hover {
  border-color: var(--sg-chat-accent);
  background: #fff;
}

.sg-chat__suggestions--followup {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  width: 94%;
  margin: -4px 0 16px;
}

.sg-chat__suggestion--chip {
  width: auto;
  max-width: 100%;
  flex: 0 1 auto;
  border-color: rgba(14, 124, 123, 0.35);
  border-radius: 999px;
  color: var(--sg-chat-accent-dark);
}

.sg-chat__suggestion--chip::before {
  content: none;
}

.sg-chat__composer-wrap {
  padding: 10px 12px 8px;
  border-top: 1px solid var(--sg-chat-soft-line);
  background: #fff;
}

.sg-chat__session-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 44px;
  margin: -5px 0 5px;
  color: var(--sg-chat-muted);
  font-size: 10.5px;
  line-height: 1.3;
}

.sg-chat__session-bar[hidden] {
  display: none;
}

.sg-chat__session-status {
  min-width: 0;
}

.sg-chat__session-status[hidden] {
  display: none;
}

.sg-chat__new-chat {
  min-height: 44px;
  flex: 0 0 auto;
  margin-left: auto;
  padding: 7px 2px;
  border: 0;
  background: transparent;
  color: var(--sg-chat-accent-dark);
  cursor: pointer;
  font: 700 11px/1.25 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.sg-chat__new-chat:hover {
  color: var(--sg-chat-ink);
}

.sg-chat__composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 7px 7px 7px 11px;
  border: 1px solid var(--sg-chat-line);
  border-radius: 9px;
  background: var(--sg-chat-bg);
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

.sg-chat__composer:focus-within {
  border-color: var(--sg-chat-accent);
  box-shadow: 0 0 0 3px rgba(14, 124, 123, 0.1);
}

.sg-chat__input {
  display: block;
  min-width: 0;
  min-height: 36px;
  max-height: 96px;
  flex: 1;
  resize: none;
  overflow-y: auto;
  padding: 7px 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--sg-chat-ink);
  font: 400 15px/1.45 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.sg-chat__input:focus-visible {
  outline: 0;
}

.sg-chat__input::placeholder {
  color: var(--sg-chat-muted);
}

.sg-chat__send {
  display: grid;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: var(--sg-chat-accent);
  color: #fff;
  cursor: pointer;
  font: 700 19px/1 sans-serif;
}

.sg-chat__send:hover {
  background: var(--sg-chat-accent-dark);
}

.sg-chat__send:disabled,
.sg-chat__input:disabled {
  cursor: wait;
  opacity: 0.55;
}

.sg-chat__verify-hint {
  margin: 6px 2px 0;
  color: var(--sg-chat-accent-dark);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
}

.sg-chat__verify-hint[hidden] {
  display: none;
}

.sg-chat__turnstile {
  display: flex;
  justify-content: center;
  max-width: 100%;
  margin-top: 6px;
  overflow: hidden;
}

.sg-chat--verify .sg-chat__turnstile {
  padding: 8px;
  border: 1px solid rgba(14, 124, 123, 0.36);
  border-radius: 7px;
  background: rgba(14, 124, 123, 0.05);
}

.sg-chat__turnstile:empty {
  display: none;
}

.sg-chat__turnstile iframe {
  max-width: 100%;
}

.sg-chat__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 2px;
  margin-top: 7px;
  color: var(--sg-chat-muted);
  font-size: 10.5px;
  line-height: 1.35;
}

.sg-chat__meta a,
.sg-chat__handoff a {
  color: var(--sg-chat-accent-dark);
  text-underline-offset: 2px;
}

.sg-chat__handoff {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 8px 14px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--sg-chat-soft-line);
  background: var(--sg-chat-bg);
  color: var(--sg-chat-muted);
  font-size: 12px;
  text-align: center;
}

.sg-chat__handoff a {
  margin-left: 5px;
  font-weight: 700;
}

.sg-chat__sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

@media (max-width: 680px), (max-width: 920px) and (max-height: 500px) {
  .sg-chat__launcher {
    right: 14px;
    bottom: calc(14px + env(safe-area-inset-bottom));
    width: 64px;
    min-height: 64px;
    justify-content: center;
    padding: 6px;
  }

  .sg-chat__launcher::after {
    content: "AI";
    position: absolute;
    top: -4px;
    right: -3px;
    display: grid;
    min-width: 22px;
    height: 18px;
    padding: 0 4px;
    place-items: center;
    border: 1px solid rgba(14, 124, 123, 0.4);
    border-radius: 999px;
    background: #fff;
    color: var(--sg-chat-accent-dark);
    font: 700 9px/1 "Spline Sans Mono", ui-monospace, monospace;
    letter-spacing: 0.04em;
  }

  .sg-chat__launcher-mark {
    width: 52px;
    height: 52px;
  }

  .sg-chat__launcher-mark img {
    width: 48px;
    height: 48px;
  }

  .sg-chat__launcher-label {
    display: none;
  }

  /* design-step1 v1.1: one primary floating surface — while the mobile CTA bar
     is visible, the launcher shrinks to a quiet 48px secondary control.
     48 = 1px border ×2 + 3px padding ×2 + 40px mark (border-box). */
  body.mobile-cta-visible:not(.menu-open) .sg-chat__launcher {
    bottom: calc(70px + env(safe-area-inset-bottom));
    width: 48px;
    height: 48px;
    min-height: 48px;
    padding: 3px;
  }

  body.mobile-cta-visible:not(.menu-open) .sg-chat__launcher::after {
    display: none;
  }

  body.mobile-cta-visible:not(.menu-open) .sg-chat__launcher-mark {
    width: 40px;
    height: 40px;
  }

  body.mobile-cta-visible:not(.menu-open) .sg-chat__launcher-mark img {
    width: 36px;
    height: 36px;
  }

  .sg-chat__dialog,
  .sg-chat__dialog[open] {
    inset: 10px;
    width: auto;
    max-width: none;
    height: calc(100dvh - 20px);
    max-height: none;
    border-radius: 10px;
  }

  .sg-chat__header {
    min-height: 64px;
  }

  .sg-chat__log {
    padding-top: 14px;
  }

  .sg-chat__input {
    font-size: 16px;
  }

  .sg-chat__bubble--rich,
  .sg-chat__suggestions--followup {
    max-width: 100%;
    width: 100%;
  }
}

/* Keep the B4 service-page CTA visible on phone and tablet layouts. */
@media (max-width: 920px) {
  body.statistical-consulting-v2 .sg-chat__launcher {
    right: 14px;
    bottom: calc(14px + env(safe-area-inset-bottom));
    width: 48px;
    height: 48px;
    min-height: 48px;
    padding: 3px;
  }

  body.statistical-consulting-v2 .sg-chat__launcher::after {
    display: none;
  }

  body.statistical-consulting-v2 .sg-chat__launcher-mark {
    width: 40px;
    height: 40px;
  }

  body.statistical-consulting-v2 .sg-chat__launcher-mark img {
    width: 36px;
    height: 36px;
  }

  body.statistical-consulting-v2 .sg-chat__launcher-label {
    display: none;
  }
}

@media (min-width: 681px) and (max-width: 1119px) and (min-height: 501px) {
  .sg-chat__dialog,
  .sg-chat__dialog[open] {
    inset: 76px 22px calc(88px + env(safe-area-inset-bottom)) auto;
    height: auto;
    max-height: none;
  }
}

@media (max-height: 620px) and (min-width: 1120px) {
  .sg-chat__dialog {
    height: calc(100dvh - 104px);
    inset-block-end: calc(88px + env(safe-area-inset-bottom));
  }
}

@media (prefers-reduced-motion: reduce) {
  .sg-chat__dialog[open],
  .sg-chat__launcher,
  .sg-chat__dots span {
    animation: none;
    transition: none;
  }
}
