/**
 * Support chat widget styles.
 *
 * Self-contained and variable-driven so the same file works on the trader client
 * (whose CSS defines --accent/--surface) and on the support console (which does
 * not). Every value falls back to a literal, so the widget is never unstyled.
 */

.sw-root {
  --sw-accent: var(--accent, #3b82f6);
  --sw-surface: var(--bg-elev, #0a101b);
  --sw-text: var(--text, #f4f8ff);
  --sw-line: var(--line, rgba(139, 172, 213, .16));
  --sw-muted: color-mix(in srgb, var(--sw-text) 58%, transparent);
  --sw-radius: var(--radius, 9px);
  --sw-shadow: var(--shadow, 0 24px 70px rgba(0, 0, 0, .48));
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  /* Clears the mobile bottom navigation bar. */
  bottom: calc(max(16px, env(safe-area-inset-bottom)) + var(--sw-lift, 0px));
  z-index: 2147483000;
  font-family: var(--font, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif);
  -webkit-tap-highlight-color: transparent;
}

/* On the H5 client the tab bar occupies the bottom edge. */
@media (max-width: 860px) {
  body.has-tabbar .sw-root,
  body[data-tabbar] .sw-root { --sw-lift: 62px; }
}

.sw-launcher {
  position: relative;
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  padding: 0;
  border: 1px solid color-mix(in srgb, var(--sw-accent) 42%, transparent);
  border-radius: 50%;
  background: linear-gradient(150deg,
      color-mix(in srgb, var(--sw-accent) 88%, #fff 0%),
      color-mix(in srgb, var(--sw-accent) 62%, #000 22%));
  color: #fff;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45), 0 0 0 0 color-mix(in srgb, var(--sw-accent) 55%, transparent);
  cursor: pointer;
  transition: transform .18s ease, box-shadow .18s ease;
  animation: sw-pulse 2.6s ease-out 1;
}

.sw-launcher:hover { transform: translateY(-2px) scale(1.03); }
.sw-launcher:active { transform: scale(.96); }
.sw-launcher:focus-visible { outline: 2px solid var(--sw-accent); outline-offset: 3px; }

@keyframes sw-pulse {
  0% { box-shadow: 0 10px 30px rgba(0, 0, 0, .45), 0 0 0 0 color-mix(in srgb, var(--sw-accent) 55%, transparent); }
  70% { box-shadow: 0 10px 30px rgba(0, 0, 0, .45), 0 0 0 16px transparent; }
  100% { box-shadow: 0 10px 30px rgba(0, 0, 0, .45), 0 0 0 0 transparent; }
}

.sw-launcher__icon svg { width: 26px; height: 26px; display: block; }
.sw-launcher__close { display: none; }
.sw-launcher__close svg { width: 22px; height: 22px; display: block; }
.sw-root--open .sw-launcher__icon { display: none; }
.sw-root--open .sw-launcher__close { display: block; }

.sw-launcher__badge {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: var(--down, #ff6174);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .5);
}
.sw-launcher__badge[hidden] { display: none; }

/* ── panel ─────────────────────────────────────────────────────────────── */
.sw-panel {
  position: absolute;
  right: 0;
  bottom: 66px;
  display: flex;
  flex-direction: column;
  width: min(372px, calc(100vw - 32px));
  height: min(560px, calc(100vh - 140px));
  overflow: hidden;
  border: 1px solid var(--sw-line);
  border-radius: 14px;
  background: var(--sw-surface);
  backdrop-filter: blur(18px);
  box-shadow: var(--sw-shadow);
  opacity: 0;
  transform: translateY(10px) scale(.98);
  transform-origin: bottom right;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}

.sw-root--open .sw-panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.sw-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--sw-line);
  background: color-mix(in srgb, var(--sw-accent) 10%, transparent);
}

.sw-head__avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 50%;
  background: color-mix(in srgb, var(--sw-accent) 20%, transparent);
  color: var(--sw-accent);
}
.sw-head__avatar svg { width: 19px; height: 19px; }

.sw-head__text { flex: 1; min-width: 0; }
.sw-head__title { font-size: 14px; font-weight: 700; color: var(--sw-text); }
.sw-head__sub {
  font-size: 11.5px;
  color: var(--sw-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sw-head__end {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--sw-muted);
  cursor: pointer;
}
.sw-head__end:hover { background: color-mix(in srgb, var(--sw-text) 10%, transparent); color: var(--sw-text); }
.sw-head__end svg { width: 16px; height: 16px; }

/* ── transcript ────────────────────────────────────────────────────────── */
.sw-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
}

.sw-msg { max-width: 86%; }
.sw-msg--in { align-self: flex-start; }
.sw-msg--out { align-self: flex-end; }

.sw-msg__meta {
  display: flex;
  gap: 6px;
  margin-bottom: 3px;
  font-size: 10.5px;
  color: var(--sw-muted);
}
.sw-msg--out .sw-msg__meta { justify-content: flex-end; }

.sw-msg__text {
  padding: 9px 12px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--sw-text);
  white-space: pre-wrap;
  word-break: break-word;
}
.sw-msg--in .sw-msg__text {
  background: color-mix(in srgb, var(--sw-text) 8%, transparent);
  border: 1px solid var(--sw-line);
  border-bottom-left-radius: 4px;
}
.sw-msg--out .sw-msg__text {
  background: var(--sw-accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.sw-msg__text a { color: inherit; text-decoration: underline; }

.sw-typing { display: flex; gap: 4px; padding: 10px 12px; align-self: flex-start; }
.sw-typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--sw-muted);
  animation: sw-blink 1.2s infinite ease-in-out;
}
.sw-typing span:nth-child(2) { animation-delay: .18s; }
.sw-typing span:nth-child(3) { animation-delay: .36s; }
@keyframes sw-blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.sw-ended {
  align-self: center;
  margin: 6px 0;
  padding: 12px 14px;
  border: 1px dashed var(--sw-line);
  border-radius: var(--sw-radius);
  text-align: center;
}
.sw-ended__text { font-size: 12.5px; color: var(--sw-muted); margin-bottom: 8px; }
.sw-ended__btn {
  padding: 7px 14px;
  border: 1px solid color-mix(in srgb, var(--sw-accent) 50%, transparent);
  border-radius: 8px;
  background: color-mix(in srgb, var(--sw-accent) 16%, transparent);
  color: var(--sw-text);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.sw-ended__btn:hover { background: color-mix(in srgb, var(--sw-accent) 26%, transparent); }

/* ── composer ──────────────────────────────────────────────────────────── */
.sw-compose {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--sw-line);
}

.sw-compose__input {
  flex: 1;
  min-height: 38px;
  max-height: 120px;
  padding: 9px 11px;
  border: 1px solid var(--sw-line);
  border-radius: 9px;
  background: color-mix(in srgb, var(--sw-text) 5%, transparent);
  color: var(--sw-text);
  font: inherit;
  font-size: 13.5px;
  line-height: 1.45;
  resize: none;
  outline: none;
}
.sw-compose__input:focus { border-color: color-mix(in srgb, var(--sw-accent) 55%, transparent); }
.sw-compose__input::placeholder { color: var(--sw-muted); }

.sw-compose__send {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: none;
  padding: 0;
  border: 0;
  border-radius: 9px;
  background: var(--sw-accent);
  color: #fff;
  cursor: pointer;
  transition: opacity .15s ease;
}
.sw-compose__send:hover { opacity: .88; }
.sw-compose__send:disabled { opacity: .4; cursor: default; }
.sw-compose__send svg { width: 18px; height: 18px; }

/* ── narrow screens: panel takes the viewport ──────────────────────────── */
@media (max-width: 520px) {
  .sw-panel {
    position: fixed;
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    height: min(78vh, 640px);
    border-radius: 16px 16px 0 0;
    transform-origin: bottom center;
  }
  .sw-launcher { width: 50px; height: 50px; }
}

@media (prefers-reduced-motion: reduce) {
  .sw-launcher { animation: none; }
  .sw-panel { transition: none; }
  .sw-typing span { animation: none; }
}

/* Final cascade: black-gold widget on every host page. */
.sw-root {
  --sw-accent: var(--accent, #d8ad52);
  --sw-surface: var(--bg-elev, #070706);
  --sw-text: var(--text, #f4f0e7);
  --sw-line: var(--line, rgba(222,184,105,.20));
}
.sw-launcher { color: #080603; background: linear-gradient(135deg, #c7963d, #f0d182 52%, #b98228); border-color: rgba(240,209,130,.34); box-shadow: 0 14px 44px rgba(0,0,0,.55), 0 0 0 1px rgba(240,209,130,.12); }
.sw-panel { background: #080806; border-color: rgba(216,173,82,.25); box-shadow: 0 28px 90px rgba(0,0,0,.72); }
.sw-panel__header, .sw-compose { background: #090907; border-color: var(--sw-line); }
.sw-compose__input { color: var(--sw-text); background: #040403; border-color: var(--sw-line); }
.sw-compose__input:focus { border-color: var(--sw-accent); box-shadow: 0 0 0 2px rgba(216,173,82,.10); }
.sw-compose__send { color: #080603; background: var(--sw-accent); }
