/* ============================================================================
   x4digital V3 — Chat SPA styles (Wow #2 surface)

   Per Charter NN#5 + feedback_aesthetic_is_signal.md: lifted, anti-templatey,
   warm. No flat panels. Gold/clay accents. All values reference design tokens.

   Layout: split — conversation pane (left ~70%) + research sidebar
   (right ~30%). On mobile (≤720px) the sidebar collapses to a bottom-sheet
   handle via the `sidebar--collapsible` mechanism in /styles/responsive.css.
   ========================================================================== */

/* ── Body / page chrome ───────────────────────────────────────────────── */
.chat-body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.chat-header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-5);
  background: rgba(250, 250, 247, 0.92);
  backdrop-filter: saturate(160%) blur(8px);
  border-bottom: 1px solid var(--ink-100);
}

.brand-mark {
  display: inline-flex;
  align-items: baseline;
  gap: var(--space-2);
  font-family: var(--font-serif);
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  color: var(--ink-900);
  letter-spacing: var(--tracking-tight);
  text-decoration: none;
}
.brand-mark::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  background: var(--gold);
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(200, 162, 74, 0.20);
}

.chat-header__right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

/* ── Shell layout ─────────────────────────────────────────────────────── */
.chat-shell {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 0;
  min-height: 0;                 /* allow inner scroll panes */
}

@media (max-width: 960px) {
  .chat-shell {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* ── Conversation pane (left) ─────────────────────────────────────────── */
.chat-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background:
    radial-gradient(ellipse at 30% -10%, rgba(200, 162, 74, 0.05), transparent 50%),
    radial-gradient(ellipse at 90% 100%, rgba(217, 81, 44, 0.04), transparent 50%),
    var(--bg);
  border-right: 1px solid var(--ink-100);
}

.chat-conversation {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-6) var(--space-5) var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  scroll-behavior: smooth;
}

/* Empty-state container is retained as a hidden hide-target referenced by
   chat.js (loadSessionHistory's hideEmpty + the typing-indicator stuck-state
   logic). The static "Tell us about your business" instructional copy +
   pills it used to carry have been replaced by the designer-greeting bubble
   rendered into the thread; see maybeRenderDesignerGreeting() in chat.js. */
.chat-empty[hidden] { display: none; }

/* Message thread */
.chat-thread {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
}

.chat-msg {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  animation: chatMsgIn var(--duration-base) var(--ease-out-expo);
}
@keyframes chatMsgIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  .chat-msg { animation: none; }
}

.chat-msg__bubble {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  max-width: 85%;
  word-wrap: break-word;
}

/* User bubble — right-aligned, clay tint */
.chat-msg--user {
  align-items: flex-end;
}
.chat-msg--user .chat-msg__bubble {
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-2) 100%);
  color: white;
  box-shadow: var(--shadow-clay);
  border-bottom-right-radius: var(--radius-sm);
}

/* Assistant bubble — left-aligned, paper, lifted. Wave 5 polish: tighter
   editorial line-height + first-letter accent so assistant turns read as
   considered prose, not generic chatbot text. We deliberately do NOT
   alternate bubble colors between turns — that read as gimmicky in
   testing; the flat-paper rhythm is calmer and matches how editorial
   columns actually breathe. */
.chat-msg--assistant {
  align-items: flex-start;
}
.chat-msg--assistant .chat-msg__bubble {
  background: var(--surface);
  color: var(--ink-900);
  box-shadow: var(--shadow-1);
  border: 1px solid var(--ink-100);
  border-bottom-left-radius: var(--radius-sm);
  /* Slightly tighter line-height — assistant prose reads denser
     than typical chat. Was --leading-normal (1.5); --leading-snug = 1.3
     gives a magazine-column feel without sacrificing scanability. */
  line-height: var(--leading-snug);
}
/* Editorial first-character treatment: the first character of each
   assistant turn gets a subtle gold-deep accent — a small typographic
   flourish that says "this is considered." Only fires on rendered prose
   (system bubbles + streaming-empty bubbles don't have a <p> child). */
.chat-msg--assistant .chat-msg__bubble > p:first-child::first-letter {
  color: var(--gold-deep);
  font-weight: var(--weight-semibold);
  font-size: 1.04em;
  letter-spacing: 0;
}

/* Designer greeting — first-impression bubble at message zero. Same warm
   paper as a regular assistant turn, with a gold left-edge accent so the
   eye reads it as the system's opening note (not a customer-side message)
   without leaning corporate. The greeting is plaintext (set via
   textContent in chat.js), so the editorial first-letter treatment above
   does not apply — the greeting reads as a direct human-voice opener,
   not formatted prose. */
.chat-msg--assistant.chat-msg--greeting .chat-msg__bubble {
  border-left: 3px solid var(--gold);
  background: linear-gradient(180deg, var(--surface) 0%, var(--gold-soft) 200%);
}

/* Markdown rendering inside assistant bubbles */
.chat-msg__bubble p { margin: 0 0 var(--space-3); }
.chat-msg__bubble p:last-child { margin-bottom: 0; }
.chat-msg__bubble strong { color: var(--ink-900); font-weight: var(--weight-semibold); }
.chat-msg__bubble em { font-style: italic; }
.chat-msg__bubble code {
  font-family: var(--font-mono);
  font-size: 0.92em;
  background: var(--surface-2);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  color: var(--ink-900);
}
.chat-msg__bubble ul, .chat-msg__bubble ol {
  margin: var(--space-2) 0;
  padding-left: var(--space-5);
}
.chat-msg__bubble li { margin-bottom: var(--space-1); }
.chat-msg__bubble a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.chat-msg__bubble a:hover { color: var(--accent-2); }
.chat-msg__bubble pre {
  background: var(--surface-2);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  margin: var(--space-2) 0;
}

.chat-msg__time {
  font-size: var(--text-xs);
  color: var(--ink-400);
  letter-spacing: var(--tracking-wide);
  padding: 0 var(--space-2);
}
.chat-msg--user .chat-msg__time { text-align: right; }

/* Status / system messages (small, muted, centered) */
.chat-msg--system {
  align-items: center;
}
.chat-msg--system .chat-msg__bubble {
  background: transparent;
  color: var(--ink-500);
  font-size: var(--text-sm);
  font-style: italic;
  box-shadow: none;
  border: none;
  padding: var(--space-2) var(--space-3);
}

/* Typing indicator. Default state is HIDDEN — toggled visible only by
   chat.js showTyping() between user_turn submit and the first assistant
   token. The [hidden] attribute is enforced with !important to defeat any
   legacy display:flex declaration that would otherwise override the
   attribute (a customer-visible polish bug if the indicator persists
   after the assistant finishes streaming). */
.chat-typing {
  display: flex;
  gap: 6px;
  padding: var(--space-3) var(--space-4);
  background: var(--surface);
  border: 1px solid var(--ink-100);
  border-radius: var(--radius-lg);
  width: fit-content;
  box-shadow: var(--shadow-0);
  margin: 0 auto 0 0;
  max-width: 760px;
}
.chat-typing[hidden] {
  display: none !important;
}
.chat-typing__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ink-400);
  animation: chatTypingPulse 1.2s ease-in-out infinite;
}
.chat-typing__dot:nth-child(2) { animation-delay: 0.15s; }
.chat-typing__dot:nth-child(3) { animation-delay: 0.30s; }
@keyframes chatTypingPulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.85); }
  40% { opacity: 1; transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .chat-typing__dot { animation: none; opacity: 0.6; }
}

/* ── Quick replies row ────────────────────────────────────────────────── */
.chat-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: 0 var(--space-5) var(--space-3);
  max-width: 760px;
  margin: 0 auto;
  width: 100%;
}
.chat-quick-reply {
  background: var(--surface);
  color: var(--ink-900);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  padding: var(--space-2) var(--space-4);
  border: 1px solid var(--ink-200);
  border-radius: var(--radius-pill);
  cursor: pointer;
  box-shadow: var(--shadow-0);
  transition: transform var(--duration-fast) var(--ease-standard),
              box-shadow var(--duration-fast) var(--ease-standard),
              background var(--duration-fast) var(--ease-standard);
}
.chat-quick-reply:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-1);
  background: var(--accent-soft);
  color: var(--accent-2);
  border-color: var(--accent);
}
.chat-quick-reply:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Greeting-pill variant — slightly warmer base so the opening options
   feel like extensions of the designer bubble above them, not generic
   chat suggestions. Hover state still matches the standard quick-reply
   pattern so the affordance reads consistently across the conversation. */
.chat-quick-reply.chat-quick-reply--greeting {
  background: linear-gradient(180deg, var(--surface) 0%, var(--gold-soft) 200%);
  border-color: var(--gold);
  color: var(--ink-900);
}
.chat-quick-reply.chat-quick-reply--greeting:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-2);
}

/* ── Inline payment gate ──────────────────────────────────────────────── */
.chat-payment-gate {
  padding: 0 var(--space-5) var(--space-3);
  max-width: 760px;
  margin: 0 auto;
  width: 100%;
  animation: chatMsgIn var(--duration-slow) var(--ease-out-expo);
}
.chat-payment-gate__inner {
  background: linear-gradient(135deg, var(--surface) 0%, var(--accent-soft) 120%);
  border: 1px solid var(--accent);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  text-align: center;
  box-shadow: var(--shadow-2);
}
.chat-payment-gate__eyebrow {
  margin: 0 0 var(--space-2);
}
.chat-payment-gate__h {
  font-family: var(--font-serif);
  font-size: var(--text-2xl);
  color: var(--ink-900);
  margin: 0 0 var(--space-2);
}
.chat-payment-gate__sub {
  color: var(--ink-700);
  font-size: var(--text-base);
  margin: 0 0 var(--space-5);
}
.chat-payment-gate__cta {
  margin-bottom: var(--space-3);
}
.chat-payment-gate__cta-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-3);
}
.chat-payment-gate__secondary {
  text-decoration: none;
}
.chat-payment-gate__fine {
  font-size: var(--text-xs);
  color: var(--ink-500);
  margin: 0;
}

/* ── Site reveal banner ───────────────────────────────────────────────── */
.chat-site-reveal {
  padding: 0 var(--space-5) var(--space-3);
  max-width: 760px;
  margin: 0 auto;
  width: 100%;
  animation: chatRevealIn var(--duration-deliberate) var(--ease-out-expo);
}
@keyframes chatRevealIn {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.chat-site-reveal__inner {
  background: linear-gradient(135deg, var(--surface) 0%, var(--gold-soft) 120%);
  border: 1px solid var(--gold);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  text-align: center;
  box-shadow: var(--shadow-2);
}
.chat-site-reveal__eyebrow {
  color: var(--gold-deep);
  margin: 0 0 var(--space-2);
}
.chat-site-reveal__h {
  font-family: var(--font-serif);
  font-size: var(--text-3xl);
  color: var(--ink-900);
  margin: 0 0 var(--space-3);
}
.chat-site-reveal__url {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: var(--text-base);
  color: var(--accent-2);
  margin: 0 0 var(--space-4);
  text-decoration: underline;
  text-underline-offset: 4px;
  word-break: break-all;
}
.chat-site-reveal__url:hover { color: var(--accent); }
.chat-site-reveal__cta {
  display: flex;
  gap: var(--space-3);
  justify-content: center;
  flex-wrap: wrap;
}

/* ── Composer ─────────────────────────────────────────────────────────── */
.chat-composer {
  padding: var(--space-3) var(--space-5) var(--space-5);
  background: var(--bg);
  border-top: 1px solid var(--ink-100);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-width: 820px;
  margin: 0 auto;
  width: 100%;
  box-sizing: border-box;
}

/* Attachment preview chips */
.chat-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  min-height: 0;
}
.chat-attachments:empty { display: none; }

.chat-attachment {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--surface);
  border: 1px solid var(--ink-200);
  border-radius: var(--radius-pill);
  padding: 4px 8px 4px 4px;
  font-size: var(--text-sm);
  color: var(--ink-700);
  box-shadow: var(--shadow-0);
}
.chat-attachment__thumb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--surface-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: var(--weight-bold);
  color: var(--ink-600);
  text-transform: uppercase;
}
.chat-attachment__thumb img {
  width: 100%; height: 100%; object-fit: cover; border-radius: 50%;
}
.chat-attachment__label {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-attachment__remove {
  background: transparent;
  border: none;
  color: var(--ink-500);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0 4px;
  border-radius: 50%;
}
.chat-attachment__remove:hover { color: var(--danger); background: var(--danger-soft); }
.chat-attachment[data-state="uploading"] { opacity: 0.7; }
.chat-attachment[data-state="failed"] { border-color: var(--danger); color: var(--danger); }

/* Composer row (button + textarea + send) */
.chat-composer__row {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
  background: var(--surface);
  border: 1px solid var(--ink-200);
  border-radius: var(--radius-xl);
  padding: var(--space-2);
  box-shadow: var(--shadow-1);
  transition: border-color var(--duration-fast) var(--ease-standard),
              box-shadow var(--duration-fast) var(--ease-standard);
}
.chat-composer__row:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow-1);
}

.chat-composer__attach,
.chat-composer__send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-600);
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--duration-fast) var(--ease-standard),
              color var(--duration-fast) var(--ease-standard),
              transform var(--duration-fast) var(--ease-standard);
}
.chat-composer__attach:hover { background: var(--surface-2); color: var(--ink-900); }

.chat-composer__send {
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-2) 100%);
  color: white;
  box-shadow: var(--shadow-clay);
}
.chat-composer__send:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: var(--shadow-clay-lift);
}
.chat-composer__send:disabled {
  background: var(--ink-200);
  color: var(--ink-400);
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.chat-composer__textarea {
  flex: 1;
  border: none;
  background: transparent;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--ink-900);
  resize: none;
  padding: var(--space-2);
  min-height: 24px;
  max-height: 200px;
  overflow-y: auto;
  outline: none;
}
.chat-composer__textarea::placeholder {
  color: var(--ink-400);
}

.chat-composer__hint {
  font-size: var(--text-xs);
  color: var(--ink-400);
  margin: 0 var(--space-2);
}
@media (max-width: 720px) {
  .chat-composer__hint { display: none; }
}

/* ── Sidebar (right) ──────────────────────────────────────────────────── */
.chat-sidebar {
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}

.chat-sidebar__handle {
  display: none; /* desktop hides handle, sidebar always open */
}

.chat-sidebar__body {
  padding: var(--space-6) var(--space-5);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.chat-sidebar__header h3 { margin-top: var(--space-1); font-size: var(--text-xl); }

/* Stages list */
.chat-stages {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.chat-stage {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  font-size: var(--text-sm);
  color: var(--ink-500);
  position: relative;
}
.chat-stage__dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--ink-200);
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: white;
  transition: background var(--duration-base) var(--ease-standard),
              box-shadow var(--duration-base) var(--ease-standard),
              transform var(--duration-base) var(--ease-out-expo);
}
.chat-stage__check {
  opacity: 0;
  transform: scale(0.4);
  transition: opacity var(--duration-base) var(--ease-out-expo),
              transform var(--duration-base) var(--ease-out-expo);
  pointer-events: none;
}
.chat-stage[data-state="active"] {
  color: var(--ink-900);
  font-weight: var(--weight-medium);
}
.chat-stage[data-state="active"] .chat-stage__dot {
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
  animation: chatStagePulse 1.6s ease-in-out infinite;
}
.chat-stage[data-state="done"] {
  color: var(--ink-700);
}
.chat-stage[data-state="done"] .chat-stage__dot {
  background: var(--success);
  box-shadow: 0 0 0 3px var(--success-soft);
  animation: none;
}
.chat-stage[data-state="done"] .chat-stage__check {
  opacity: 1;
  transform: scale(1);
  animation: chatStageCheckIn var(--duration-slow) var(--ease-out-expo);
}
@keyframes chatStagePulse {
  0%, 100% { box-shadow: 0 0 0 4px var(--accent-soft); transform: scale(1); }
  50%      { box-shadow: 0 0 0 9px rgba(217, 81, 44, 0.10); transform: scale(1.06); }
}
@keyframes chatStageCheckIn {
  0%   { opacity: 0; transform: scale(0.2) rotate(-12deg); }
  60%  { opacity: 1; transform: scale(1.18) rotate(2deg); }
  100% { opacity: 1; transform: scale(1) rotate(0); }
}

/* All-done gold shimmer. When the last stage (live) flips to active, the
   sidebar's stages list as a whole gets a one-shot diagonal shimmer that
   sweeps left→right across all the now-completed dots — the visual analog
   of "and we're done." chat.js adds .chat-stages--all-done when stage=live.
   Single-shot, self-cleaning class — the JS strips it after 2s so reconnects
   mid-deploy don't re-fire. */
.chat-stages--all-done {
  position: relative;
  overflow: hidden;
}
.chat-stages--all-done::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    100deg,
    transparent 0%,
    transparent 35%,
    rgba(200, 162, 74, 0.40) 50%,
    transparent 65%,
    transparent 100%
  );
  background-size: 250% 100%;
  pointer-events: none;
  animation: chatStagesShimmer 1.6s var(--ease-out-expo) 1 forwards;
  border-radius: var(--radius-md);
}
@keyframes chatStagesShimmer {
  0%   { background-position: 200% 0; opacity: 0; }
  20%  { opacity: 1; }
  80%  { opacity: 1; }
  100% { background-position: -100% 0; opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .chat-stage[data-state="active"] .chat-stage__dot { animation: none; }
  .chat-stage[data-state="done"] .chat-stage__check { animation: none; }
  .chat-stages--all-done::after { animation: none; opacity: 0; }
}

/* ── Findings panel (branded section + sticky header on scroll) ───────── */
.chat-findings-panel {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  /* Negative-margin trick lets the sticky header span the sidebar padding
     edge-to-edge while the section itself still aligns with siblings. */
  margin: 0 calc(var(--space-5) * -1);
  padding: 0 var(--space-5);
}
.chat-findings-panel__header {
  position: sticky;
  /* Stick under the sidebar's top padding so it never overlaps the stage
     tracker. The body has `padding: var(--space-6) var(--space-5)`. */
  top: calc(var(--space-6) * -1);
  z-index: 5;
  margin: 0;
  padding: var(--space-3) var(--space-5);
  background: linear-gradient(180deg, var(--surface-2) 0%, var(--surface-2) 80%, rgba(245, 240, 232, 0));
  display: flex;
  flex-direction: column;
  gap: 2px;
  /* Header is hidden until the first finding lands so the empty placeholder
     doesn't get a visual chrome overhead. .has-findings flips this on. */
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
  transition: opacity var(--duration-base) var(--ease-standard),
              transform var(--duration-base) var(--ease-standard);
}
.chat-findings-panel.has-findings .chat-findings-panel__header {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.chat-findings-panel__title {
  font-family: var(--font-serif);
  font-size: var(--text-lg);
  color: var(--ink-900);
  margin: 0;
  letter-spacing: var(--tracking-tight);
}

/* Findings list */
.chat-findings {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.chat-findings__empty {
  color: var(--ink-500);
  font-size: var(--text-sm);
  font-style: italic;
}
.chat-finding {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--surface);
  border: 1px solid var(--ink-100);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--ink-700);
  box-shadow: var(--shadow-0);
  animation: chatFindingIn var(--duration-slow) var(--ease-out-expo) backwards;
}
/* Staggered reveal: each finding lands ~50ms after the prior one. We cap
   at :nth-child(8) so a long list still feels lively without a crawl.
   Beyond that they snap in with no extra delay. */
.chat-finding:nth-child(1) { animation-delay: 0ms; }
.chat-finding:nth-child(2) { animation-delay: 50ms; }
.chat-finding:nth-child(3) { animation-delay: 100ms; }
.chat-finding:nth-child(4) { animation-delay: 150ms; }
.chat-finding:nth-child(5) { animation-delay: 200ms; }
.chat-finding:nth-child(6) { animation-delay: 250ms; }
.chat-finding:nth-child(7) { animation-delay: 300ms; }
.chat-finding:nth-child(8) { animation-delay: 350ms; }
@keyframes chatFindingIn {
  from { opacity: 0; transform: translateX(8px); }
  to   { opacity: 1; transform: translateX(0); }
}
@media (prefers-reduced-motion: reduce) {
  .chat-finding { animation: none; }
}
.chat-finding__icon {
  flex-shrink: 0;
  font-size: 14px;
  line-height: 1.2;
  display: inline-flex;
  width: 18px;
  justify-content: center;
  /* Default ink color; per-kind overrides below paint web/gbp/attachment. */
  color: var(--ink-500);
  transition: color var(--duration-fast) var(--ease-standard);
}
.chat-finding[data-state="active"] .chat-finding__icon {
  color: var(--accent);
  animation: chatFindingSearch 1.2s ease-in-out infinite;
}
.chat-finding[data-state="done"] .chat-finding__icon { color: var(--success); }
.chat-finding[data-state="failed"] .chat-finding__icon { color: var(--danger); }
.chat-finding[data-state="failed"] { border-color: var(--danger-soft); }
@keyframes chatFindingSearch {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}
.chat-finding__text { flex: 1; line-height: var(--leading-snug); }

/* Kind-specific icon coloring — visual taxonomy of where a finding came from.
   The orchestrator emits `kind` in findings_update bullets (web search /
   GBP lookup / attachment extract / page build); CSS surfaces that source
   so the customer reads "what we're doing" at a glance, not just "we're
   doing things." Active+failed states still override (red/clay take
   precedence over kind tint) — the source label is informational, the
   active/failed signal is operational. */
.chat-finding.finding--web .chat-finding__icon,
.chat-finding.finding--web-search .chat-finding__icon,
.chat-finding.finding--fetch-url .chat-finding__icon,
.chat-finding.finding--fetch_url .chat-finding__icon {
  color: var(--accent-2);
}
.chat-finding.finding--gbp .chat-finding__icon,
.chat-finding.finding--gbp-lookup .chat-finding__icon,
.chat-finding.finding--gbp_lookup .chat-finding__icon,
.chat-finding.finding--screenshot .chat-finding__icon {
  color: var(--gold-deep);
}
.chat-finding.finding--attachment .chat-finding__icon,
.chat-finding.finding--read-attachment .chat-finding__icon,
.chat-finding.finding--read_attachment .chat-finding__icon,
.chat-finding.finding--upload .chat-finding__icon {
  color: var(--ink-700);
}
/* Per-kind border tint on the left edge — a 2px accent stripe so the eye
   can scan the column for "type" without reading every line. Subtle enough
   to feel editorial, not compete with the icon. */
.chat-finding.finding--web,
.chat-finding.finding--web-search,
.chat-finding.finding--fetch-url,
.chat-finding.finding--fetch_url {
  border-left: 2px solid var(--accent-soft);
}
.chat-finding.finding--gbp,
.chat-finding.finding--gbp-lookup,
.chat-finding.finding--gbp_lookup,
.chat-finding.finding--screenshot {
  border-left: 2px solid var(--gold-soft);
}
.chat-finding.finding--attachment,
.chat-finding.finding--read-attachment,
.chat-finding.finding--read_attachment,
.chat-finding.finding--upload {
  border-left: 2px solid var(--ink-200);
}

/* Stage pill (compact, in header) */
.chat-stage-pill {
  font-size: var(--text-xs);
}

/* ── Mobile: sidebar collapses to bottom-sheet ────────────────────────── */
@media (max-width: 720px) {
  .chat-shell {
    grid-template-columns: 1fr;
  }
  .chat-sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface);
    border-top: 1px solid var(--ink-100);
    border-top-left-radius: var(--radius-xl);
    border-top-right-radius: var(--radius-xl);
    box-shadow: var(--shadow-3);
    z-index: 30;
    max-height: 70vh;
    transform: translateY(calc(100% - 56px));
    transition: transform var(--duration-slow) var(--ease-out-expo);
  }
  .chat-sidebar[aria-expanded="true"] {
    transform: translateY(0);
  }
  .chat-sidebar__handle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    height: 56px;
    padding: 0 var(--space-5);
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--ink-700);
    font-family: var(--font-sans);
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
  }
  .chat-sidebar__handle-caret {
    transition: transform var(--duration-base) var(--ease-standard);
  }
  .chat-sidebar[aria-expanded="true"] .chat-sidebar__handle-caret {
    transform: rotate(180deg);
  }
  .chat-sidebar__body {
    max-height: calc(70vh - 56px);
    overflow-y: auto;
  }
  .chat-conversation {
    padding-bottom: 80px; /* keep above the sheet handle */
  }
  .chat-composer {
    padding-bottom: 76px; /* leave room for sheet handle */
  }
}

/* ── Auth modal (signup-or-login overlay) ────────────────────────────── */
.chat-auth-modal[hidden] { display: none; }
.chat-auth-modal__lede {
  margin: 0 0 var(--space-5);
  color: var(--ink-700);
  font-size: var(--text-base);
  line-height: var(--leading-snug);
}
.chat-auth-modal__tabs {
  margin-bottom: var(--space-5);
}
.chat-auth-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.chat-auth-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.chat-auth-field__label {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--ink-700);
}
.chat-auth-field__hint {
  font-size: var(--text-xs);
  color: var(--ink-500);
}
.chat-auth-form__error {
  background: var(--danger-soft);
  color: var(--danger);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  margin: 0;
}
.chat-auth-form__submit {
  margin-top: var(--space-2);
  justify-content: center;
}

/* ============================================================================
   W2C: drag-drop, ACK/retry resilience, attachment progress, site-reveal flair
   ========================================================================== */

/* Drag-over composer cue. Applied to .chat-composer when files are being
   dragged over it. Wave 5 polish: stronger clay glow + dotted overlay.
   The composer row gets a clay border AND a 2-layer ring (inner solid clay
   + outer dotted clay), so it visually says "drop zone" instead of "input
   field with a tint". Layout never shifts — all visual weight lives in
   borders + box-shadow. */
.chat-composer.composer--dragover .chat-composer__row {
  border-color: var(--accent);
  background: var(--accent-soft);
  /* Layered shadows: inner solid ring (3px clay-soft) + outer dotted glow
     (8px wider, accent at 16% opacity). The dotted feel comes from the
     CSS variable on the composer itself drawing dashes via background. */
  box-shadow:
    inset 0 0 0 1px var(--accent),
    0 0 0 4px var(--accent-soft),
    0 0 0 8px rgba(217, 81, 44, 0.10),
    var(--shadow-2);
}
/* Dotted dashed overlay across the composer row — visible via a CSS-image
   border on a pseudo-element so the textarea + buttons stay clickable. The
   dashes pulse to reinforce "yes, drop here, not somewhere else." */
.chat-composer.composer--dragover .chat-composer__row::before {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: calc(var(--radius-xl) + 2px);
  border: 2px dashed var(--accent);
  pointer-events: none;
  animation: chatDragDashes 1.4s ease-in-out infinite;
}
.chat-composer__row { position: relative; }
@keyframes chatDragDashes {
  0%, 100% { opacity: 0.55; }
  50%      { opacity: 0.95; }
}
.chat-composer.composer--dragover::after {
  content: "Drop to attach";
  position: absolute;
  inset: auto var(--space-5) calc(100% + var(--space-2)) var(--space-5);
  text-align: center;
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--accent-2);
  background: var(--accent-soft);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  pointer-events: none;
  animation: chatDragHintIn var(--duration-fast) var(--ease-out-expo);
  box-shadow: 0 2px 8px rgba(217, 81, 44, 0.18);
}
.chat-composer { position: relative; }
@keyframes chatDragHintIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  .chat-composer.composer--dragover::after { animation: none; }
  .chat-composer.composer--dragover .chat-composer__row::before { animation: none; }
}

/* ── Attachment chip states (uploading already exists; add ready + failed +
   extraction status). The W1E `attachment_extraction_progress` event drives
   `data-extraction` via JS; the chip then surfaces the right pill. */
.chat-attachment[data-state="ready"] {
  border-color: var(--success);
}
.chat-attachment__status {
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  font-weight: var(--weight-semibold);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
}
.chat-attachment[data-extraction="extracting"] .chat-attachment__status {
  background: var(--accent-soft);
  color: var(--accent-2);
}
.chat-attachment[data-extraction="ready"] .chat-attachment__status {
  background: var(--success-soft);
  color: var(--success);
}
.chat-attachment[data-extraction="failed"] .chat-attachment__status {
  background: var(--danger-soft);
  color: var(--danger);
}
.chat-attachment[data-extraction="extracting"] .chat-attachment__status::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  margin-right: 6px;
  vertical-align: middle;
  animation: chatAttachmentPulse 1.2s ease-in-out infinite;
}
@keyframes chatAttachmentPulse {
  0%, 100% { opacity: 0.4; transform: scale(0.85); }
  50%      { opacity: 1; transform: scale(1.1); }
}
@media (prefers-reduced-motion: reduce) {
  .chat-attachment[data-extraction="extracting"] .chat-attachment__status::before { animation: none; }
}

/* ── ACK/retry: pending user bubble (in-flight, awaiting server ack) ─── */
.chat-msg--user.chat-msg--pending .chat-msg__bubble {
  opacity: 0.78;
  filter: saturate(0.85);
}

/* ── ACK/retry: failed user bubble + tap-to-retry affordance ───────────── */
.chat-msg--user.chat-msg--failed .chat-msg__bubble {
  opacity: 0.55;
  border: 1px dashed var(--danger);
}
.chat-msg__retry {
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--danger);
  background: var(--danger-soft);
  border: 1px solid var(--danger);
  border-radius: var(--radius-pill);
  padding: 4px 12px;
  margin-top: var(--space-1);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-standard),
              color var(--duration-fast) var(--ease-standard),
              transform var(--duration-fast) var(--ease-standard);
  align-self: flex-end;
}
.chat-msg__retry:hover {
  background: var(--danger);
  color: white;
  transform: translateY(-1px);
}
.chat-msg__retry:focus-visible {
  outline: 2px solid var(--danger);
  outline-offset: 2px;
}

/* ── Site-reveal celebration: URL pill scale-bump + section glow ──────── */
.chat-site-reveal--celebrating .chat-site-reveal__inner {
  animation: chatCelebrationGlow 2.5s var(--ease-out-expo);
}
.chat-site-reveal--celebrating .chat-site-reveal__url {
  display: inline-block;
  animation: chatUrlPillBump var(--duration-deliberate) var(--ease-out-expo);
}
@keyframes chatCelebrationGlow {
  0%   { box-shadow: var(--shadow-2); }
  35%  { box-shadow: 0 0 0 6px rgba(200, 162, 74, 0.20), 0 14px 38px rgba(200, 162, 74, 0.30); }
  100% { box-shadow: var(--shadow-2); }
}
@keyframes chatUrlPillBump {
  0%   { transform: scale(0.9); }
  55%  { transform: scale(1.05); }
  100% { transform: scale(1.0); }
}
@media (prefers-reduced-motion: reduce) {
  .chat-site-reveal--celebrating .chat-site-reveal__inner,
  .chat-site-reveal--celebrating .chat-site-reveal__url { animation: none; }
}

/* Confetti canvas — fixed full-viewport overlay. Pointer-events disabled
   so the user can keep clicking the URL/CTA underneath. */
.chat-confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 80;
}
