/* =========================================================================
 * widget.css — styles for the support chat widget only.
 * Kept apart from styles.css so the widget can be lifted into another site by
 * copying `widget/` + `config.js` and adding two tags to the page.
 * ========================================================================= */

.rd-widget {
  --rd-brand: #2f6df6;
  --rd-brand-dark: #1f4fc4;
  --rd-surface: #ffffff;
  --rd-surface-alt: #f2f5fb;
  --rd-ink: #10151f;
  --rd-ink-soft: #56607a;
  --rd-line: #e0e6f1;
  --rd-danger: #b3261e;
  --rd-danger-bg: #fdecea;
  --rd-shadow: 0 20px 52px rgba(16, 21, 31, 0.22);

  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 90;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  font-family: var(--font, system-ui, sans-serif);
}

@media (prefers-color-scheme: dark) {
  .rd-widget {
    --rd-surface: #141b29;
    --rd-surface-alt: #1c2536;
    --rd-ink: #eef2f8;
    --rd-ink-soft: #aab4c7;
    --rd-line: #2a3550;
    --rd-danger: #ff8f85;
    --rd-danger-bg: #35191a;
    --rd-shadow: 0 20px 52px rgba(0, 0, 0, 0.6);
  }
}

/* ── launcher ───────────────────────────────────────────────────────────── */
.rd-launcher {
  order: 2;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 13px 20px;
  border: none;
  border-radius: 999px;
  background: var(--rd-brand);
  color: #fff;
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  box-shadow: 0 10px 26px rgba(47, 109, 246, 0.36);
  transition: background-color 0.15s ease, transform 0.15s ease;
}
.rd-launcher:hover {
  background: var(--rd-brand-dark);
  transform: translateY(-1px);
}
.rd-launcher:focus-visible {
  outline: 3px solid var(--rd-brand);
  outline-offset: 3px;
}
.rd-launcher__icon {
  font-size: 1.05rem;
  line-height: 1;
}
.rd-launcher__label {
  white-space: nowrap;
}

/* ── panel ──────────────────────────────────────────────────────────────── */
.rd-panel {
  order: 1;
  width: min(380px, calc(100vw - 32px));
  /* --mw-attribution-height is the demo attribution banner pinned to the top of
   * the viewport (see vendor/attribution-banner/). Subtracting it keeps the top
   * of the open panel — and therefore its whole scrolled transcript — clear of
   * the banner on short viewports. The `0px` fallback is what makes this widget
   * still correct when it is lifted into a site that has no such banner, which
   * is the point of keeping widget/ self-contained. */
  height: min(560px, calc(100vh - 130px - var(--mw-attribution-height, 0px)));
  display: flex;
  flex-direction: column;
  background: var(--rd-surface);
  color: var(--rd-ink);
  border: 1px solid var(--rd-line);
  border-radius: 16px;
  box-shadow: var(--rd-shadow);
  overflow: hidden;
}
.rd-panel[hidden] {
  display: none;
}

.rd-panel__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 14px 12px 18px;
  border-bottom: 1px solid var(--rd-line);
  background: var(--rd-surface-alt);
}
.rd-panel__heading {
  min-width: 0;
}
.rd-panel__title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.rd-panel__sub {
  margin: 2px 0 0;
  font-size: 0.78rem;
  color: var(--rd-ink-soft);
}
.rd-panel__actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: none;
}

.rd-textbtn,
.rd-iconbtn {
  border: 1px solid transparent;
  background: transparent;
  color: var(--rd-ink-soft);
  font: inherit;
  font-size: 0.8rem;
  border-radius: 8px;
  padding: 5px 9px;
  cursor: pointer;
}
.rd-textbtn:hover,
.rd-iconbtn:hover {
  background: var(--rd-surface);
  border-color: var(--rd-line);
  color: var(--rd-ink);
}
.rd-iconbtn {
  font-size: 0.9rem;
  line-height: 1;
  padding: 6px 8px;
}

/* ── transcript ─────────────────────────────────────────────────────────── */
.rd-transcript {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.rd-msg {
  max-width: 86%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 0.92rem;
  line-height: 1.45;
}
.rd-msg__text {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.rd-msg__detail {
  margin: 6px 0 0;
  font-size: 0.72rem;
  opacity: 0.75;
  font-variant-numeric: tabular-nums;
}

.rd-msg--user {
  align-self: flex-end;
  background: var(--rd-brand);
  color: #fff;
  border-bottom-right-radius: 5px;
}
.rd-msg--assistant {
  align-self: flex-start;
  background: var(--rd-surface-alt);
  color: var(--rd-ink);
  border: 1px solid var(--rd-line);
  border-bottom-left-radius: 5px;
}
.rd-msg--error {
  align-self: stretch;
  max-width: 100%;
  background: var(--rd-danger-bg);
  color: var(--rd-danger);
  border: 1px solid currentColor;
}

/* typing indicator */
.rd-msg--pending {
  padding: 12px 14px;
}
.rd-dots {
  display: inline-flex;
  gap: 4px;
}
.rd-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--rd-ink-soft);
  animation: rd-bounce 1.1s infinite ease-in-out;
}
.rd-dot:nth-child(2) {
  animation-delay: 0.16s;
}
.rd-dot:nth-child(3) {
  animation-delay: 0.32s;
}
@keyframes rd-bounce {
  0%,
  70%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }
  35% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

/* ── composer ───────────────────────────────────────────────────────────── */
.rd-composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--rd-line);
  background: var(--rd-surface);
}
.rd-composer__input {
  flex: 1;
  resize: none;
  min-height: 42px;
  max-height: 140px;
  padding: 10px 12px;
  border: 1px solid var(--rd-line);
  border-radius: 11px;
  background: var(--rd-surface-alt);
  color: var(--rd-ink);
  font: inherit;
  font-size: 0.92rem;
  line-height: 1.4;
}
.rd-composer__input:focus-visible {
  outline: 2px solid var(--rd-brand);
  outline-offset: 1px;
}
.rd-composer__input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.rd-send {
  flex: none;
  padding: 11px 16px;
  border: none;
  border-radius: 11px;
  background: var(--rd-brand);
  color: #fff;
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
}
.rd-send:hover:not(:disabled) {
  background: var(--rd-brand-dark);
}
.rd-send:disabled {
  opacity: 0.6;
  cursor: progress;
}

.rd-panel__foot {
  margin: 0;
  padding: 0 14px 12px;
  font-size: 0.7rem;
  color: var(--rd-ink-soft);
  text-align: center;
}

.rd-widget[data-config-error="true"] .rd-launcher {
  background: var(--rd-danger);
  box-shadow: none;
}

.rd-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) {
  .rd-widget {
    right: 12px;
    bottom: 12px;
    left: 12px;
    align-items: stretch;
  }
  .rd-launcher {
    justify-content: center;
  }
  .rd-panel {
    width: 100%;
    /* Same reasoning as above; on a phone the banner is two rows tall, so the
     * subtraction matters more here than it does on the desktop layout. */
    height: min(72vh, 560px, calc(100vh - 90px - var(--mw-attribution-height, 0px)));
  }
}

@media (prefers-reduced-motion: reduce) {
  .rd-dot {
    animation: none;
  }
  .rd-transcript {
    scroll-behavior: auto;
  }
}
