/**
 * chat-widget.css
 * ─────────────────────────────────────────────────────────────
 * Floating AI assistant. Loaded on both portals, so every selector is
 * namespaced under .ssg-chat to avoid colliding with style.css or support.css.
 *
 * Colours are scoped to the widget rather than inherited, because the two
 * portals define different token sets under the same names.
 * ─────────────────────────────────────────────────────────────
 */

.ssg-chat {
  --c-brand:     #f2652a;
  --c-brand-dk:  #d1491a;
  --c-surface:   #ffffff;
  --c-panel:     #f8fafc;
  --c-text:      #0f172a;
  --c-muted:     #64748b;
  --c-border:    #e2e8f0;
  --c-bubble-me: #f2652a;
  --c-shadow:    0 20px 52px rgba(15, 23, 42, .26);

  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 2147483000;   /* above Bootstrap modals and Mapbox controls */
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  color: var(--c-text);
}

.ssg-chat[data-theme="dark"] {
  --c-surface: #161b22;
  --c-panel:   #1c232d;
  --c-text:    #e7e9ec;
  --c-muted:   #9aa2b0;
  --c-border:  #2b333f;
  --c-shadow:  0 20px 52px rgba(0, 0, 0, .58);
}

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

/* ── Launcher ─────────────────────────────────────────────────────────────── */
/* A speech-bubble launcher rather than a bare disc: the tail reads as "chat",
   and the label tells people what it is before they click. The mark is an
   orange M on a white square, so it sits in its own white badge and keeps its
   colour on both the light and dark consoles. */
.ssg-chat__launcher {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 17px 9px 9px;
  background: var(--c-surface);
  border: 1.5px solid var(--c-border);
  border-radius: 999px 999px 8px 999px;   /* bottom-right corner = the tail root */
  cursor: pointer;
  box-shadow: var(--c-shadow);
  position: relative;
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
}
.ssg-chat__launcher:hover {
  transform: translateY(-2px);
  border-color: var(--c-brand);
  box-shadow: 0 22px 46px rgba(242, 101, 42, .32);
}
.ssg-chat__launcher[hidden] { display: none; }

/* The tail — a small triangle tucked under the bottom-right corner. */
.ssg-chat__launcher::after {
  content: "";
  position: absolute; right: -1px; bottom: -8px;
  border-left: 11px solid transparent;
  border-top: 12px solid var(--c-surface);
  filter: drop-shadow(1px 1px 0 var(--c-border));
}

.ssg-chat__launcher-badge {
  position: relative; flex: none;
  width: 40px; height: 40px; border-radius: 50%;
  background: #fff; overflow: hidden;
  border: 2px solid var(--c-brand);
  display: grid; place-items: center;
}
.ssg-chat__launcher-logo { width: 100%; height: 100%; object-fit: cover; display: block; }

/* "Live" dot — the assistant is ready, not a static image. */
.ssg-chat__launcher-badge::after {
  content: "";
  position: absolute; right: -1px; bottom: -1px;
  width: 11px; height: 11px; border-radius: 50%;
  background: #22c55e; border: 2px solid var(--c-surface);
  animation: ssg-live 2.4s ease-in-out infinite;
}
@keyframes ssg-live {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, .55); }
  50%      { box-shadow: 0 0 0 5px rgba(34, 197, 94, 0); }
}

.ssg-chat__launcher-text {
  display: flex; flex-direction: column; align-items: flex-start;
  line-height: 1.25; text-align: left;
}
.ssg-chat__launcher-title {
  font-size: 13.5px; font-weight: 700; color: var(--c-text); white-space: nowrap;
}
.ssg-chat__launcher-sub {
  font-size: 10.5px; font-weight: 600; color: var(--c-muted);
  letter-spacing: .04em; white-space: nowrap;
}

/* ── Panel ────────────────────────────────────────────────────────────────── */
.ssg-chat__panel {
  width: min(408px, calc(100vw - 32px));
  height: min(620px, calc(100vh - 100px));
  min-width: 320px; min-height: 380px;
  max-width: calc(100vw - 32px); max-height: calc(100vh - 44px);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: 16px;
  box-shadow: var(--c-shadow);
  display: flex; flex-direction: column;
  overflow: hidden;
  /* Resizable from the bottom-right corner; the panel is anchored bottom-right
     so we flip the resize handle to the top-left via `direction`. */
  resize: both;
}
.ssg-chat__panel[hidden] { display: none; }

.ssg-chat__head {
  display: flex; align-items: center; gap: 11px;
  padding: 13px 15px;
  background: var(--c-panel);
  border-bottom: 1px solid var(--c-border);
  flex: none;
}
.ssg-chat__avatar {
  width: 32px; height: 32px; border-radius: 9px; flex: none;
  background: #fff; color: var(--c-brand);
  object-fit: cover; overflow: hidden;
  border: 1px solid var(--c-border);
  font-weight: 800; font-size: 13px;
}
.ssg-chat__title { font-weight: 700; font-size: 14px; line-height: 1.2; }
.ssg-chat__status { font-size: 11.5px; color: var(--c-muted); }
.ssg-chat__spacer { flex: 1; }
.ssg-chat__icon-btn {
  background: none; border: 0; cursor: pointer; color: var(--c-muted);
  padding: 5px; border-radius: 7px; display: grid; place-items: center;
}
.ssg-chat__icon-btn:hover { background: rgba(127, 127, 127, .14); color: var(--c-text); }
.ssg-chat__icon-btn svg { width: 17px; height: 17px; }

/* ── Log ──────────────────────────────────────────────────────────────────── */
.ssg-chat__log {
  flex: 1; overflow-y: auto; padding: 17px 15px;
  display: flex; flex-direction: column; gap: 13px;
  overscroll-behavior: contain;
}

.ssg-chat__msg { max-width: 88%; }
.ssg-chat__msg--user { align-self: flex-end; }
.ssg-chat__msg--bot  { align-self: flex-start; }

.ssg-chat__bubble {
  padding: 10px 13px; border-radius: 13px;
  white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere;
}
.ssg-chat__msg--user .ssg-chat__bubble {
  background: var(--c-bubble-me); color: #fff; border-bottom-right-radius: 4px;
}
.ssg-chat__msg--bot .ssg-chat__bubble {
  background: var(--c-panel); border: 1px solid var(--c-border);
  border-bottom-left-radius: 4px;
}
.ssg-chat__bubble strong { font-weight: 700; }
.ssg-chat__bubble code {
  background: rgba(127, 127, 127, .18); padding: .08em .34em;
  border-radius: 4px; font-size: .88em;
}

/* Tool status line, e.g. "Searching the knowledge base…" */
.ssg-chat__tool {
  align-self: flex-start;
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--c-muted); font-style: italic;
  padding: 2px 2px 2px 4px;
}
.ssg-chat__tool::before {
  content: ""; width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid var(--c-border); border-top-color: var(--c-brand);
  animation: ssg-spin .7s linear infinite;
}
@keyframes ssg-spin { to { transform: rotate(360deg); } }

/* Typing indicator */
.ssg-chat__typing { align-self: flex-start; display: flex; gap: 4px; padding: 11px 13px; }
.ssg-chat__typing span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--c-muted);
  animation: ssg-bounce 1.2s infinite ease-in-out;
}
.ssg-chat__typing span:nth-child(2) { animation-delay: .16s; }
.ssg-chat__typing span:nth-child(3) { animation-delay: .32s; }
@keyframes ssg-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .45; }
  30%           { transform: translateY(-5px); opacity: 1; }
}

/* Ticket confirmation card */
.ssg-chat__ticket {
  align-self: flex-start; max-width: 88%;
  border: 1px solid var(--c-brand); border-radius: 12px;
  background: rgba(242, 101, 42, .07);
  padding: 12px 14px;
}
.ssg-chat__ticket-no {
  font-weight: 800; color: var(--c-brand); font-size: 15px;
  font-variant-numeric: tabular-nums;
}
.ssg-chat__ticket-meta { font-size: 12.5px; color: var(--c-muted); margin-top: 3px; }

.ssg-chat__error {
  align-self: stretch;
  background: rgba(239, 68, 68, .1); border: 1px solid rgba(239, 68, 68, .4);
  color: #b91c1c; border-radius: 10px; padding: 10px 13px; font-size: 13px;
}
.ssg-chat[data-theme="dark"] .ssg-chat__error { color: #fca5a5; }

/* ── Suggestions ──────────────────────────────────────────────────────────── */
.ssg-chat__suggestions {
  display: flex; flex-direction: column; gap: 7px;
  padding: 0 15px 12px;
}
.ssg-chat__suggestions:empty { padding: 0; }
.ssg-chat__suggestions-label {
  font-size: 10.5px; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--c-muted);
  padding-top: 2px;
}
.ssg-chat__suggestion {
  text-align: left; cursor: pointer;
  background: var(--c-surface); color: var(--c-text);
  border: 1px solid var(--c-border); border-radius: 9px;
  padding: 8px 12px; font-size: 13px; font-weight: 500;
  transition: border-color .13s, background .13s;
}
.ssg-chat__suggestion:hover { border-color: var(--c-brand); background: var(--c-panel); }
.ssg-chat__suggestion--more {
  display: flex; align-items: center; gap: 6px;
  color: var(--c-brand); font-weight: 700;
  background: transparent; border-style: dashed;
}
.ssg-chat__suggestion-plus {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--c-brand); color: #fff;
  font-size: 12px; line-height: 1; flex-shrink: 0;
}

/* ── Composer ─────────────────────────────────────────────────────────────── */
.ssg-chat__composer {
  display: flex; align-items: flex-end; gap: 9px;
  padding: 11px 13px; border-top: 1px solid var(--c-border);
  background: var(--c-panel); flex: none;
}
.ssg-chat__input {
  flex: 1; resize: none; max-height: 116px;
  padding: 9px 12px; border-radius: 10px;
  border: 1px solid var(--c-border);
  background: var(--c-surface); color: var(--c-text);
  font-family: inherit; font-size: 13.5px; line-height: 1.45;
}
.ssg-chat__input:focus {
  outline: none; border-color: var(--c-brand);
  box-shadow: 0 0 0 3px rgba(242, 101, 42, .14);
}
.ssg-chat__send {
  width: 38px; height: 38px; flex: none; border: 0; border-radius: 10px;
  background: var(--c-brand); color: #fff; cursor: pointer;
  display: grid; place-items: center;
}
.ssg-chat__send:disabled { opacity: .45; cursor: not-allowed; }
.ssg-chat__send svg { width: 17px; height: 17px; }

.ssg-chat__foot {
  padding: 0 13px 9px; background: var(--c-panel);
  font-size: 10.5px; color: var(--c-muted); text-align: center;
}

/* ── Accessibility / motion ───────────────────────────────────────────────── */
.ssg-chat :focus-visible { outline: 2px solid var(--c-brand); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  .ssg-chat__launcher, .ssg-chat__suggestion { transition: none; }
  .ssg-chat__typing span, .ssg-chat__tool::before,
  .ssg-chat__launcher-badge::after { animation: none; }
}

/* On a narrow screen the label would crowd the page, so the bubble collapses
   back to the badge. The tail stays, so it still reads as chat. */
@media (max-width: 560px) {
  .ssg-chat { right: 12px; bottom: 12px; }
  .ssg-chat__launcher { padding: 8px; border-radius: 999px 999px 8px 999px; }
  .ssg-chat__launcher-text { display: none; }
  .ssg-chat__panel { width: calc(100vw - 24px); height: calc(100vh - 96px); resize: none; }
}
