/* ============================================================
   SCG Chat Assistant — floating launcher + slide-up panel.
   Token-aware (dark + light). Respects prefers-reduced-motion.
   ============================================================ */

.scg-chat { position: fixed; right: 20px; bottom: 20px; z-index: 95; }
.scg-chat[hidden] { display: none; }

/* ---------- Launcher (always visible) ---------- */
.scg-chat-launcher {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 13px 22px 13px 18px; border-radius: 999px;
  background: var(--scg-teal); color: var(--on-teal, #04211E);
  font-family: 'Inter', system-ui, sans-serif;
  font-weight: 600; font-size: 15px; line-height: 1; letter-spacing: 0.01em;
  cursor: pointer; border: none;
  box-shadow: 0 12px 36px rgba(20, 184, 166, 0.36), 0 2px 8px rgba(0, 0, 0, 0.18);
  transition: transform 0.22s ease, box-shadow 0.22s ease;
}
.scg-chat-launcher:hover { transform: translateY(-2px); box-shadow: 0 16px 42px rgba(20, 184, 166, 0.42), 0 2px 10px rgba(0, 0, 0, 0.22); }
.scg-chat-launcher:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 3px; }
.scg-chat-launcher-icon { width: 18px; height: 18px; flex-shrink: 0; }
.scg-chat.is-open .launcher-icon-closed { display: none; }
.scg-chat:not(.is-open) .launcher-icon-open { display: none; }
.scg-chat.is-open .scg-chat-launcher-label { display: none; }
@media (max-width: 600px) {
  .scg-chat-launcher { padding: 12px 16px; font-size: 13px; }
  .scg-chat-launcher-label { display: none; }
  .scg-chat:not(.is-open) .scg-chat-launcher { padding: 14px; }
}

/* ---------- Panel ---------- */
.scg-chat-panel {
  position: absolute; right: 0; bottom: calc(100% + 14px);
  width: min(380px, calc(100vw - 40px));
  height: min(560px, calc(100vh - 120px));
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.50), 0 6px 18px rgba(0, 0, 0, 0.25);
  opacity: 0; transform: translateY(12px) scale(0.98);
  transform-origin: bottom right;
  transition: opacity 0.22s ease, transform 0.22s ease;
  pointer-events: none;
}
.scg-chat.is-open .scg-chat-panel { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }
.scg-chat-panel[hidden] { display: none; }

@media (max-width: 600px) {
  .scg-chat-panel {
    width: calc(100vw - 24px); right: -8px;
    height: calc(100vh - 100px); height: calc(100dvh - 100px);
    border-radius: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .scg-chat-launcher, .scg-chat-panel { transition: none; }
}

/* ---------- Header ---------- */
.scg-chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 14px 14px 16px;
  background: linear-gradient(135deg, var(--bg-mid), var(--bg-elev));
  border-bottom: 1px solid var(--border);
}
.scg-chat-header-left { display: flex; align-items: center; gap: 12px; }
.scg-chat-avatar { width: 36px; height: 36px; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; }
.scg-chat-avatar svg { width: 100%; height: 100%; filter: drop-shadow(0 2px 8px rgba(20, 184, 166, 0.25)); }
.scg-chat-title { font-size: 14px; font-weight: 600; color: var(--text); letter-spacing: -0.01em; }
.scg-chat-subtitle { font-family: 'Inter', system-ui, sans-serif; font-weight: 600; font-size: 10.5px; color: var(--text-mute); letter-spacing: 0.06em; text-transform: uppercase; display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.scg-chat-status-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 6px var(--accent); animation: scg-chat-status 2.2s ease-in-out infinite; }
@keyframes scg-chat-status { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
@media (prefers-reduced-motion: reduce) { .scg-chat-status-dot { animation: none; } }

.scg-chat-close {
  width: 32px; height: 32px; border-radius: 8px; background: transparent;
  border: none; color: var(--text-mute); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
}
.scg-chat-close:hover { background: var(--surface-mid); color: var(--text); }
.scg-chat-close svg { width: 16px; height: 16px; }

/* ---------- Messages ---------- */
.scg-chat-messages {
  flex: 1; overflow-y: auto;
  padding: 18px 16px 14px; display: flex; flex-direction: column; gap: 14px;
  scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent;
}
.scg-chat-messages::-webkit-scrollbar { width: 6px; }
.scg-chat-messages::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

.scg-chat-msg { display: flex; max-width: 100%; }
.scg-chat-msg-user { justify-content: flex-end; }
.scg-chat-msg-assistant { justify-content: flex-start; }

.scg-chat-bubble {
  max-width: 86%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px; line-height: 1.55;
  word-wrap: break-word; overflow-wrap: break-word;
}
.scg-chat-msg-user .scg-chat-bubble {
  background: var(--accent); color: var(--text-on-accent);
  border-bottom-right-radius: 4px; font-weight: 500;
}
.scg-chat-msg-assistant .scg-chat-bubble {
  background: var(--surface-mid); color: var(--text);
  border: 1px solid var(--border); border-bottom-left-radius: 4px;
}
.scg-chat-bubble p { margin: 0; }
.scg-chat-bubble p + p { margin-top: 8px; }
.scg-chat-bubble em { color: var(--text); font-style: italic; }

/* CTA button rendered from <ctaLink/> token in assistant responses */
.scg-chat-cta {
  display: inline-flex; align-items: center; gap: 8px;
  margin-top: 12px; padding: 10px 16px;
  background: var(--scg-amber); color: var(--scg-amber-text);
  border-radius: 9px; font-weight: 600; font-size: 13px;
  text-decoration: none; transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  box-shadow: 0 4px 14px rgba(240, 169, 59, 0.28);
}
.scg-chat-cta:hover { background: var(--scg-amber-600); transform: translateY(-1px); box-shadow: 0 6px 18px rgba(240, 169, 59, 0.36); }
.scg-chat-cta svg { width: 13px; height: 13px; }

/* Typing indicator */
.scg-chat-typing { display: inline-flex; gap: 4px; padding: 12px 14px; align-items: center; }
.scg-chat-typing span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--text-mute);
  animation: scg-chat-typing 1.4s ease-in-out infinite;
}
.scg-chat-typing span:nth-child(2) { animation-delay: 0.18s; }
.scg-chat-typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes scg-chat-typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) { .scg-chat-typing span { animation: none; } }

.scg-chat-error {
  margin: 4px 16px 8px; padding: 10px 12px;
  background: rgba(226, 75, 74, 0.10);
  border: 1px solid rgba(226, 75, 74, 0.30);
  color: #F0A9A8; font-size: 12.5px; line-height: 1.5;
  border-radius: 8px;
}
:root[data-theme="light"] .scg-chat-error { color: #B23230; background: rgba(226, 75, 74, 0.08); }

/* ---------- Input ---------- */
.scg-chat-input-wrap {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 12px 12px 8px; border-top: 1px solid var(--border);
  background: var(--bg-elev);
}
.scg-chat-input-wrap textarea {
  flex: 1; resize: none;
  padding: 10px 12px;
  border: 1px solid var(--border-strong); border-radius: 10px;
  background: var(--surface-soft); color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px; line-height: 1.45;
  max-height: 120px; min-height: 40px;
  transition: border-color 0.15s ease;
}
.scg-chat-input-wrap textarea::placeholder { color: var(--text-mute); }
.scg-chat-input-wrap textarea:focus { outline: none; border-color: var(--accent); }

.scg-chat-send {
  width: 40px; height: 40px; border-radius: 10px;
  background: var(--accent); color: var(--text-on-accent);
  border: none; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.scg-chat-send:hover:not(:disabled) { transform: translateY(-1px); }
.scg-chat-send:disabled { opacity: 0.4; cursor: not-allowed; }
.scg-chat-send svg { width: 16px; height: 16px; }

.scg-chat-footnote {
  padding: 4px 16px 12px; text-align: center;
  font-size: 10.5px; color: var(--text-faint);
  font-family: 'Inter', system-ui, sans-serif;
  letter-spacing: 0.04em;
}

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

/* Suppress the sticky CTA whenever the chat is mounted (chat IS the CTA) */
.sticky-cta { display: none !important; }
