/* The in-house assistant bubble and window. Colours come from theme.css tokens so it
   follows the light/dark theme; the fallbacks keep it readable if a token is missing.
   The z-index matches the hosted widget it replaced, so the tour Help button
   (2147483645) still sits just below the open window on mobile. */
.upfront-chat {
  --uc-brand: var(--brand, #2b57d6);
  --uc-on-brand: var(--on-brand, #ffffff);
  --uc-surface: var(--surface, #ffffff);
  --uc-surface-2: var(--surface-2, #f1f4f9);
  --uc-line: var(--line, #e5e9f0);
  --uc-tx: var(--tx, #101828);
  --uc-tx-2: var(--tx-2, #5a6478);
  --uc-tx-3: var(--tx-3, #8b95a7);
  --uc-radius: var(--radius-lg, 14px);
  --uc-shadow: var(--shadow, 0 12px 32px -12px rgba(16, 24, 40, .35));
  --uc-font: var(--font-ui, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif);
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 2147483646;
  font-family: var(--uc-font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--uc-tx);
}

.upfront-chat__bubble {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 50%;
  background: var(--uc-brand);
  color: var(--uc-on-brand);
  box-shadow: 0 8px 24px rgba(16, 24, 40, .28);
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease;
}
.upfront-chat__bubble:hover { transform: translateY(-1px); box-shadow: 0 12px 28px rgba(16, 24, 40, .34); }
.upfront-chat__bubble:focus-visible { outline: 3px solid var(--uc-on-brand); outline-offset: 2px; }
.upfront-chat__icon--close { display: none; }
.upfront-chat--open .upfront-chat__icon--open { display: none; }
.upfront-chat--open .upfront-chat__icon--close { display: block; }

.upfront-chat__window {
  position: absolute;
  right: 0;
  bottom: 72px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 110px);
  display: flex;
  flex-direction: column;
  background: var(--uc-surface);
  border: 1px solid var(--uc-line);
  border-radius: var(--uc-radius);
  box-shadow: var(--uc-shadow);
  overflow: hidden;
}
.upfront-chat__window[hidden] { display: none; }

.upfront-chat__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  background: var(--uc-brand);
  color: var(--uc-on-brand);
}
.upfront-chat__title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.upfront-chat__title strong { display: block; font-size: 15px; line-height: 1.2; }
.upfront-chat__title small { display: block; font-size: 12px; opacity: .85; }
.upfront-chat__dot { width: 10px; height: 10px; border-radius: 50%; background: #4ade80; box-shadow: 0 0 0 3px rgba(74, 222, 128, .3); flex: none; }
.upfront-chat__header-actions { display: flex; align-items: center; gap: 4px; }
.upfront-chat__reset,
.upfront-chat__close {
  border: 0;
  background: rgba(255, 255, 255, .14);
  color: inherit;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
}
.upfront-chat__reset { font-size: 12px; padding: 5px 9px; }
.upfront-chat__close { font-size: 22px; line-height: 1; width: 30px; height: 30px; }
.upfront-chat__reset:hover, .upfront-chat__close:hover { background: rgba(255, 255, 255, .26); }

.upfront-chat__messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 14px 14px 6px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
.upfront-chat__msg {
  max-width: 88%;
  padding: 9px 12px;
  border-radius: 14px;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.upfront-chat__msg--user {
  align-self: flex-end;
  background: var(--uc-brand);
  color: var(--uc-on-brand);
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}
.upfront-chat__msg--assistant {
  align-self: flex-start;
  background: var(--uc-surface-2);
  color: var(--uc-tx);
  border-bottom-left-radius: 4px;
}
.upfront-chat__msg--assistant p { margin: 0 0 8px; }
.upfront-chat__msg--assistant p:last-child { margin-bottom: 0; }
.upfront-chat__msg--assistant ul, .upfront-chat__msg--assistant ol { margin: 0 0 8px 18px; padding: 0; }
.upfront-chat__msg--assistant li { margin: 2px 0; }
.upfront-chat__msg--assistant a { color: var(--uc-brand); text-decoration: underline; }
.upfront-chat__table-wrap { overflow-x: auto; margin: 0 0 8px; }
.upfront-chat__table { border-collapse: collapse; font-size: 13px; width: 100%; }
.upfront-chat__table th, .upfront-chat__table td {
  border: 1px solid var(--uc-line);
  padding: 4px 7px;
  text-align: left;
  white-space: nowrap;
}
.upfront-chat__table th { background: var(--uc-surface); font-weight: 600; }
.upfront-chat__table td:not(:first-child), .upfront-chat__table th:not(:first-child) { text-align: right; }
.upfront-chat__msg--assistant code {
  font-family: var(--font-mono, ui-monospace, Menlo, Consolas, monospace);
  font-size: 13px;
  background: rgba(127, 127, 127, .15);
  padding: 1px 4px;
  border-radius: 4px;
}
.upfront-chat__msg--status {
  align-self: flex-start;
  color: var(--uc-tx-3);
  font-size: 13px;
  font-style: italic;
  padding: 2px 4px;
}
.upfront-chat__msg--error {
  align-self: stretch;
  background: var(--down-soft, #fbe9ec);
  color: var(--down, #d1364a);
  font-size: 14px;
}
.upfront-chat__typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.upfront-chat__typing i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--uc-tx-3);
  animation: upfront-chat-blink 1.2s infinite ease-in-out;
}
.upfront-chat__typing i:nth-child(2) { animation-delay: .2s; }
.upfront-chat__typing i:nth-child(3) { animation-delay: .4s; }
@keyframes upfront-chat-blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.upfront-chat__suggestions { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 14px 8px; }
.upfront-chat__suggestions:empty { display: none; }
.upfront-chat__chip {
  border: 1px solid var(--uc-line);
  background: var(--uc-surface);
  color: var(--uc-brand);
  border-radius: 999px;
  padding: 5px 11px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.upfront-chat__chip:hover { background: var(--uc-surface-2); }

.upfront-chat__form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 10px 6px 14px;
  border-top: 1px solid var(--uc-line);
  background: var(--uc-surface);
}
.upfront-chat__input {
  flex: 1 1 auto;
  resize: none;
  max-height: 120px;
  border: 1px solid var(--uc-line);
  border-radius: 10px;
  background: var(--uc-surface-2);
  color: var(--uc-tx);
  padding: 8px 10px;
  font: inherit;
  line-height: 1.4;
}
.upfront-chat__input:focus { outline: 2px solid var(--uc-brand); outline-offset: 0; border-color: transparent; }
.upfront-chat__send {
  flex: none;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 10px;
  background: var(--uc-brand);
  color: var(--uc-on-brand);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.upfront-chat__send:disabled { opacity: .5; cursor: default; }
.upfront-chat__footnote {
  margin: 0;
  padding: 0 14px 8px;
  font-size: 11px;
  color: var(--uc-tx-3);
  text-align: center;
}

@media (max-width: 480px) {
  .upfront-chat { right: 12px; bottom: 12px; }
  .upfront-chat__window {
    position: fixed;
    inset: 0;
    width: auto;
    max-width: none;
    height: auto;
    max-height: none;
    border-radius: 0;
    border: 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  .upfront-chat__bubble { transition: none; }
  .upfront-chat__messages { scroll-behavior: auto; }
  .upfront-chat__typing i { animation: none; opacity: .6; }
}
