/* Safeguard floating AI chat widget */

.sg-chat {
  --sg-chat-blue: var(--sg-blue, #1769A1);
  --sg-chat-orange: var(--sg-orange, #FB7523);
  --sg-chat-navy: var(--sg-navy, #0C2D44);
  --sg-chat-ink: var(--sg-ink, #1E2A33);
  --sg-chat-muted: var(--sg-muted, #5A6B77);
  --sg-chat-line: var(--sg-line, #D7E3EC);
  --sg-chat-wash: var(--sg-blue-wash, #ffffff);
  --sg-chat-font-head: var(--sg-font-head, "Chakra Petch", ui-sans-serif, sans-serif);
  --sg-chat-font-body: var(--sg-font-body, "Inter", ui-sans-serif, system-ui, sans-serif);
  --sg-chat-ease: cubic-bezier(0.16, 1, 0.3, 1);
  --sg-chat-dur: 0.32s;

  position: fixed;
  right: clamp(1rem, 3vw, 1.5rem);
  bottom: clamp(1rem, 3vw, 1.5rem);
  z-index: 110;
  font-family: var(--sg-chat-font-body);
}

body:has(.sg-mobile-bar:not([aria-hidden="true"])) .sg-chat {
  bottom: calc(4.75rem + env(safe-area-inset-bottom, 0px));
}

.sg-chat__toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 3.25rem;
  min-width: 3.25rem;
  padding: 0 1.1rem 0 0.95rem;
  border: 0;
  border-radius: 999px;
  background: var(--sg-chat-blue);
  color: #fff;
  font-family: var(--sg-chat-font-head);
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(12, 45, 68, 0.22);
  transition:
    background 0.2s ease,
    box-shadow 0.28s var(--sg-chat-ease),
    padding 0.28s var(--sg-chat-ease),
    border-radius 0.28s var(--sg-chat-ease),
    transform 0.28s var(--sg-chat-ease);
}

.sg-chat__toggle:hover {
  background: var(--sg-blue-dark, #125882);
  transform: translateY(-1px);
}

.sg-chat.is-open .sg-chat__toggle {
  padding: 0;
  border-radius: 50%;
  transform: translateY(0);
}

.sg-chat__toggle:focus-visible {
  outline: 2px solid var(--sg-chat-orange);
  outline-offset: 3px;
}

.sg-chat__toggle .sg-lucide-icon,
.sg-chat__close .sg-lucide-icon,
.sg-chat__send .sg-lucide-icon {
  width: var(--sg-icon-size-sm, 1.125rem);
  height: var(--sg-icon-size-sm, 1.125rem);
  color: currentColor;
}

.sg-chat__toggle-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    opacity 0.22s ease,
    transform 0.28s var(--sg-chat-ease);
}

.sg-chat__toggle-icon--close {
  position: absolute;
  opacity: 0;
  transform: rotate(-45deg) scale(0.65);
}

.sg-chat.is-open .sg-chat__toggle-icon--open {
  opacity: 0;
  transform: rotate(45deg) scale(0.65);
}

.sg-chat.is-open .sg-chat__toggle-icon--close {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

.sg-chat__toggle-label {
  max-width: 4rem;
  overflow: hidden;
  white-space: nowrap;
  transition:
    opacity 0.22s ease,
    max-width 0.28s var(--sg-chat-ease),
    margin 0.28s var(--sg-chat-ease);
}

.sg-chat.is-open .sg-chat__toggle-label {
  max-width: 0;
  opacity: 0;
  margin: 0;
}

.sg-chat__panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + 0.75rem);
  display: flex;
  flex-direction: column;
  width: min(100vw - 2rem, 22rem);
  height: min(70vh, 32rem);
  border: 1px solid var(--sg-chat-line);
  background: #fff;
  box-shadow: 0 18px 50px rgba(12, 45, 68, 0.18);
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(0.85rem) scale(0.94);
  transform-origin: bottom right;
  transition:
    opacity var(--sg-chat-dur) var(--sg-chat-ease),
    transform var(--sg-chat-dur) var(--sg-chat-ease),
    visibility 0s linear var(--sg-chat-dur);
}

.sg-chat.is-open .sg-chat__panel {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0) scale(1);
  transition:
    opacity var(--sg-chat-dur) var(--sg-chat-ease),
    transform var(--sg-chat-dur) var(--sg-chat-ease),
    visibility 0s linear 0s;
}

.sg-chat__head {
  display: flex;
  flex-shrink: 0;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1rem 0.85rem;
  border-bottom: 1px solid var(--sg-chat-line);
  background: var(--sg-chat-wash);
}

.sg-chat__head-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

.sg-chat__new {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2rem;
  padding: 0.3rem 0.65rem;
  border: 1px solid var(--sg-chat-line);
  border-radius: 999px;
  background: #fff;
  color: var(--sg-chat-navy);
  font-family: var(--sg-chat-font-body);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
}

.sg-chat__new:hover,
.sg-chat__new:focus-visible {
  border-color: var(--sg-chat-blue);
  color: var(--sg-chat-blue);
  background: #fff;
}

.sg-chat__eyebrow {
  margin: 0;
  font-family: var(--sg-chat-font-head);
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--sg-chat-blue);
}

.sg-chat__title {
  margin: 0.2rem 0 0;
  font-family: var(--sg-chat-font-head);
  font-size: 1.125rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--sg-chat-navy);
}

.sg-chat__close {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--sg-chat-muted);
  cursor: pointer;
}

.sg-chat__close:hover {
  color: var(--sg-chat-navy);
}

.sg-chat__messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 0;
  padding: 1rem;
  overflow-y: auto;
  background: #fff;
}

.sg-chat__inline-actions {
  align-self: stretch;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.15rem;
}

.sg-chat__welcome-actions {
  margin-top: 0.35rem;
  padding-top: 0.15rem;
}

.sg-chat__chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.25rem;
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--sg-chat-line);
  border-radius: 999px;
  background: #fff;
  color: var(--sg-chat-navy);
  font-family: var(--sg-chat-font-body);
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.sg-chat .sg-chat__chip:hover,
.sg-chat .sg-chat__chip:focus-visible {
  background: var(--sg-chat-wash);
  border-color: var(--sg-chat-blue);
  color: var(--sg-chat-navy);
}

.sg-chat__chip--primary {
  background: var(--sg-chat-wash);
  border-color: var(--sg-chat-blue);
  color: var(--sg-chat-blue);
}

.sg-chat .sg-chat__chip--primary:hover,
.sg-chat .sg-chat__chip--primary:focus-visible {
  background: var(--sg-chat-blue);
  border-color: var(--sg-chat-blue);
  color: #fff;
}

.sg-chat__chip--link {
  color: var(--sg-chat-blue);
}

.sg-chat .sg-chat__chip--link:hover,
.sg-chat .sg-chat__chip--link:focus-visible {
  color: var(--sg-chat-navy);
}

/* Legacy action class, keep readable on theme button:hover overrides */
.sg-chat__action {
  flex: 1 1 calc(50% - 0.25rem);
  min-height: 2.25rem;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--sg-chat-line);
  border-radius: 999px;
  background: #fff;
  color: var(--sg-chat-navy);
  font-family: var(--sg-chat-font-body);
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.sg-chat .sg-chat__action:hover,
.sg-chat .sg-chat__action:focus-visible {
  background: var(--sg-chat-wash);
  border-color: var(--sg-chat-blue);
  color: var(--sg-chat-navy);
}

.sg-chat__quote-card {
  align-self: stretch;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.85rem;
  border: 1px solid var(--sg-chat-line);
  background: #fff;
}

.sg-chat__quote-title {
  margin: 0;
  font-family: var(--sg-chat-font-head);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--sg-chat-muted);
}

.sg-chat__quote-total {
  margin: 0;
  font-family: var(--sg-chat-font-head);
  font-size: 1.375rem;
  font-weight: 700;
  color: var(--sg-chat-navy);
}

.sg-chat__quote-meta {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--sg-chat-muted);
}

.sg-chat__quote-list {
  margin: 0.25rem 0 0;
  padding-left: 1.1rem;
  font-size: 0.8125rem;
  color: var(--sg-chat-ink);
}

.sg-chat__quote-form {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-top: 0.35rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--sg-chat-line);
}

.sg-chat__quiz {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.sg-chat__route-card {
  align-self: stretch;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.85rem;
  border: 1px solid var(--sg-chat-line);
  background: var(--sg-chat-wash);
}

.sg-chat__route-link {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--sg-chat-blue);
  text-decoration: none;
}

.sg-chat__route-link:hover {
  text-decoration: underline;
}

.sg-chat__lead {
  align-self: stretch;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  box-sizing: border-box;
  width: 100%;
  margin: 0;
  padding: 0.9rem;
  border: 1px solid var(--sg-chat-line);
  background: var(--sg-chat-wash);
}

.sg-chat__handoff-form {
  background: #fff;
  border-color: #c7d9e8;
  box-shadow: 0 1px 0 rgba(15, 45, 74, 0.04);
}

.sg-chat__handoff-title {
  margin: 0;
  font-family: var(--sg-chat-font-head);
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--sg-chat-navy);
}

.sg-chat__field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  width: 100%;
  box-sizing: border-box;
}

.sg-chat__label {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--sg-chat-muted);
}

.sg-chat__field-input {
  box-sizing: border-box;
  width: 100%;
  min-height: 2.5rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--sg-chat-line);
  border-radius: 0;
  background: #fff;
  font-family: var(--sg-chat-font-body);
  font-size: 0.875rem;
  line-height: 1.3;
  color: var(--sg-chat-ink);
  appearance: none;
}

.sg-chat__field-input:focus {
  outline: 2px solid var(--sg-chat-blue);
  outline-offset: 0;
  border-color: var(--sg-chat-blue);
}

.sg-chat__lead-submit {
  box-sizing: border-box;
  width: 100%;
  min-height: 2.75rem;
  margin-top: 0.15rem;
  padding: 0.65rem 0.85rem;
  border: 0;
  background: var(--sg-chat-orange);
  color: #fff;
  font-family: var(--sg-chat-font-head);
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
}

.sg-chat__lead-submit:hover:not(:disabled) {
  background: var(--sg-orange-deep, #EA7914);
}

.sg-chat__lead-submit:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.sg-chat__agent-escape {
  margin-top: 0.25rem;
  padding-top: 0.35rem;
  border-top: 1px solid var(--sg-chat-line);
}

.sg-chat__msg {
  max-width: 92%;
  padding: 0.65rem 0.85rem;
  font-size: 0.875rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.sg-chat__msg--bot {
  align-self: flex-start;
  background: var(--sg-chat-wash);
  color: var(--sg-chat-ink);
}

.sg-chat__msg--agent {
  align-self: flex-start;
  background: #e8f5e9;
  color: var(--sg-chat-ink);
  border: 1px solid #a5d6a7;
}

.sg-chat__msg--system {
  align-self: center;
  background: transparent;
  color: var(--sg-chat-muted);
  font-size: 0.8125rem;
  font-style: italic;
  padding: 0.25rem 0.5rem;
}

.sg-chat__msg--user {
  align-self: flex-end;
  background: var(--sg-chat-blue);
  color: #fff;
}

.sg-chat__msg--typing {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  color: var(--sg-chat-muted);
  font-style: normal;
}

.sg-chat__typing-label {
  font-size: 0.875rem;
}

.sg-chat__typing-dots {
  display: inline-flex;
  align-items: flex-end;
  gap: 0.2rem;
  height: 1rem;
  margin-left: 0.1rem;
}

.sg-chat__typing-dots span {
  display: block;
  width: 0.35rem;
  height: 0.35rem;
  border-radius: 50%;
  background: var(--sg-chat-blue);
  animation: sg-chat-dot 1.2s ease-in-out infinite;
}

.sg-chat__typing-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.sg-chat__typing-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes sg-chat-dot {
  0%,
  60%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }

  30% {
    opacity: 1;
    transform: translateY(-0.35rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  .sg-chat__typing-dots span {
    animation: none;
    opacity: 0.7;
  }

  .sg-chat__panel,
  .sg-chat__toggle,
  .sg-chat__toggle-icon,
  .sg-chat__toggle-label {
    transition: none;
  }

  .sg-chat__panel {
    transform: none;
  }

  .sg-chat.is-open .sg-chat__panel {
    transform: none;
  }
}

.sg-chat__form {
  display: flex;
  flex-shrink: 0;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.75rem;
  border-top: 1px solid var(--sg-chat-line);
  background: #fff;
}

.sg-chat__input {
  flex: 1;
  min-height: 2.75rem;
  max-height: 6rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--sg-chat-line);
  border-radius: 0;
  resize: none;
  font-family: var(--sg-chat-font-body);
  font-size: 0.875rem;
  line-height: 1.4;
  color: var(--sg-chat-ink);
}

.sg-chat__input:focus {
  outline: 2px solid var(--sg-chat-blue);
  outline-offset: 0;
  border-color: var(--sg-chat-blue);
}

.sg-chat__send {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border: 0;
  background: var(--sg-chat-orange);
  color: #fff;
  cursor: pointer;
}

.sg-chat__send:hover:not(:disabled) {
  background: var(--sg-orange-deep, #EA7914);
}

.sg-chat__send:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

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

@media (max-width: 480px) {
  .sg-chat__panel {
    width: min(100vw - 1.25rem, 22rem);
    height: min(72vh, 28rem);
  }

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

  .sg-chat__toggle {
    width: 3.25rem;
    min-width: 3.25rem;
    padding: 0;
    border-radius: 50%;
  }
}

.hidden {
  display: none !important;
}

.sg-chat__quote-intro {
  margin: 0 0 0.5rem;
  font-size: 0.8125rem;
  line-height: 1.45;
  color: var(--sg-chat-muted);
}

.sg-chat__quote-summary {
  margin: 0 0 0.75rem;
  padding-left: 1.1rem;
  font-size: 0.8125rem;
  line-height: 1.4;
  color: var(--sg-chat-ink);
}

.sg-chat__otp-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.sg-chat__otp-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
  padding: 0.65rem;
  border: 1px solid var(--sg-chat-line);
  background: var(--sg-chat-wash);
}

.sg-chat__otp-input {
  flex: 1 1 6rem;
  min-width: 6rem;
  text-align: center;
  letter-spacing: 0.25em;
}

.sg-chat__otp-verified {
  margin: 0.35rem 0 0;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--sg-chat-blue);
}

.sg-chat__otp-hint {
  flex: 1 1 100%;
  margin: 0;
  font-size: 0.75rem;
  color: var(--sg-chat-muted);
}

.sg-chat__consent {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin: 0.65rem 0;
  font-size: 0.8125rem;
  line-height: 1.35;
  color: var(--sg-chat-ink);
}
