/* =====================================================================
   Chat assistant widget (spec docs/superpowers/specs/2026-11-29-chatbot-instant-answers-design.md section 8).
   Loaded by _LayoutPx right before the widget markup. Mobile-first: a full-height modal sheet below 768px,
   a non-modal panel above the launcher from 768px. Tokens come from px.css.
   ===================================================================== */

/* ---------- Launcher (shown only when JavaScript runs) ---------- */
.px-chat-launcher { display: none; }
.js .px-chat-launcher {
  position: fixed; right: var(--px-gutter); bottom: calc(16px + var(--px-bar-h) + var(--px-cookie-h, 0px)); z-index: 95;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; min-width: 52px; min-height: 52px; padding: 0 14px;
  border: 0; border-radius: 999px; background: var(--px-cta); color: var(--px-on-cta); font: 700 1.1875rem/1 var(--px-font-body);
  cursor: pointer;
}
.js .px-chat-launcher[aria-expanded="true"] { display: none; }
/* Phones: the launcher waits until the homepage hero scrolls away, so it never sits on the hero buttons. */
@media (max-width: 767.98px) { .js.px-hero-in-view .px-chat-launcher { display: none; } }
/* Icon-only on phones, but the label stays in the accessibility tree as the button's name. */
.px-chat-launcher__label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Panel: full-height sheet on phones ---------- */
.px-chat {
  position: fixed; inset: 0; z-index: 96; box-sizing: border-box; width: 100%; max-width: 100%; height: 100%; max-height: 100%;
  margin: 0; padding: 0; border: 0; background: var(--px-surface); color: var(--px-text); font: 400 1rem/1.55 var(--px-font-body);
}
.px-chat[open] { display: flex; flex-direction: column; }
.px-chat::backdrop { background: rgba(8, 7, 6, 0.6); }

.px-chat__head { display: flex; align-items: flex-start; gap: 0.5rem; padding: calc(12px + env(safe-area-inset-top)) 12px 12px 18px; border-bottom: 1px solid var(--px-line); }
.px-chat__head > div { flex: 1; min-width: 0; }
.px .px-chat__title { margin: 0; font: 700 1.125rem/1.3 var(--px-font-head); letter-spacing: -0.01em; }
.px .px-chat__sub { margin: 2px 0 0; font-size: 0.875rem; color: var(--px-muted); }
.px-chat__icon-btn { display: inline-grid; place-items: center; flex: none; width: 44px; height: 44px; border: 1px solid var(--px-line-strong); border-radius: 10px; background: transparent; color: var(--px-text); cursor: pointer; }
.px-chat__icon-btn:hover { border-color: var(--px-text); }

/* ---------- Conversation ---------- */
.px-chat__log { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 12px; padding: 16px; }
.px-chat__msg { max-width: 92%; padding: 12px 14px; border-radius: 14px; overflow-wrap: anywhere; }
.px .px-chat__msg p { margin: 0 0 0.5em; }
.px .px-chat__msg p:last-of-type { margin-bottom: 0; }
.px-chat__msg--bot { align-self: flex-start; background: var(--px-surface-2); border: 1px solid var(--px-line); border-bottom-left-radius: 4px; }
.px-chat__msg--user { align-self: flex-end; background: var(--px-amber); color: var(--px-on-amber); border-bottom-right-radius: 4px; }
.px-chat__list { margin: 0.25em 0 0.5em; padding-left: 1.2em; }
.px-chat__list li { margin: 0.2em 0; }
.px .px-chat__notice { color: var(--px-gold); }
.px-chat__links { list-style: none; margin: 0.5em 0 0; padding: 0; }
.px-chat__actions, .px-chat__chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.px .px-chat .px-btn--sm { min-height: 44px; padding: 0.5rem 0.95rem; border-radius: 10px; font-size: 0.9375rem; }
/* Cream text on the brand colour is 3.57:1, so primary buttons keep large (19px bold) text to meet WCAG AA. */
.px .px-chat .px-btn--sm.px-btn--primary { font-size: 1.1875rem; font-weight: 700; }
.px-chat__chip {
  min-height: 44px; padding: 0.5rem 0.85rem; border: 1px solid var(--px-line-strong); border-radius: 999px;
  background: transparent; color: var(--px-text); font: 500 0.9375rem/1.3 var(--px-font-body); text-align: left; cursor: pointer;
}
.px-chat__chip:hover { border-color: var(--px-amber); color: var(--px-gold); }
.px-chat__pending { color: var(--px-muted); }
@media (prefers-reduced-motion: no-preference) {
  .px-chat__pending { animation: px-chat-pulse 1.2s ease-in-out infinite; }
  @keyframes px-chat-pulse { 50% { opacity: 0.45; } }
}

/* ---------- Composer ---------- */
.px-chat__form { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--px-line); }
.px-chat__form input {
  flex: 1; min-width: 0; min-height: 48px; padding: 0 14px; border: 1px solid var(--px-line-strong); border-radius: 12px;
  background: var(--px-surface-2); color: var(--px-text); font: 400 1rem var(--px-font-body);
}
.px-chat__form input::placeholder { color: var(--px-muted); opacity: 1; }
.px-chat__form input:focus-visible { outline: 2px solid var(--px-amber); outline-offset: 1px; }
.px-chat__send { display: inline-grid; place-items: center; flex: none; width: 48px; min-height: 48px; border: 0; border-radius: 12px; background: var(--px-cta); color: var(--px-on-cta); cursor: pointer; }
.px-chat__form[aria-busy="true"] .px-chat__send { opacity: 0.6; cursor: progress; }
.px .px-chat__privacy { margin: 0; padding: 0 16px calc(12px + env(safe-area-inset-bottom)); font-size: 0.875rem; color: var(--px-muted); }

/* ---------- Tablet and desktop: floating panel above the launcher ---------- */
@media (min-width: 768px) {
  .px-chat-launcher__label { position: static; width: auto; height: auto; overflow: visible; clip: auto; }
  .js .px-chat-launcher { padding: 0 20px 0 16px; }
  .px-chat {
    inset: auto var(--px-gutter) calc(16px + var(--px-cookie-h, 0px)) auto;
    width: min(400px, 100vw - 2 * var(--px-gutter));
    height: min(640px, 100vh - var(--px-header-h) - 32px - var(--px-cookie-h, 0px));
    height: min(640px, 100dvh - var(--px-header-h) - 32px - var(--px-cookie-h, 0px));
    border: 1px solid var(--px-line-strong); border-radius: var(--px-radius-lg); box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55); overflow: hidden;
  }
  .px-chat__head { padding-top: 12px; }
  .px .px-chat__privacy { padding-bottom: 12px; }
}
