/* chat.css — Message bubbles, chips, typing indicator, disabled input, scroll
   Wave 1.3 / Wave 7 A.1: bubble issue fixes */

/* ── Bubble token defaults (overridden per skin) ── */
:root {
  --bubble-radius: 16px;
  --bubble-shadow: none;
  --bubble-ai-bg: var(--bg-elev);
  --bubble-ai-fg: var(--fg);
  --bubble-ai-border: 1px solid var(--border);
  --bubble-user-bg: var(--accent);
  --bubble-user-fg: #fff;
  --bubble-user-border: none;
  --chip-bg: var(--bg-elev);
  --chip-fg: var(--fg);
  --chip-border: var(--border);
}

/* ── Message list ── */
.message-list {
  list-style: none;
  padding: 16px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
  /* Cap the readable line length on wide desktops — at full panel width the
     chat ran ~985px/line, well past the ~75ch comfortable-reading ceiling.
     Unconditional: harmless on mobile (the panel is < 760px so width:100%
     fills it) and on desktop it centres the column via auto inline margins. */
  max-width: 760px;
  margin-inline: auto;
  width: 100%;
}

/* Wave 8 P5.4: empty-state placeholder. After clearChat() (restart, persona
   switch, deep-link before the first beat lands), the chat panel was a blank
   void. The placeholder uses `data-empty-text` set by JS so the string is
   i18n-driven; CSS shows it only while the list has no children. Italic +
   muted reads as ambient narration rather than a UI control. */
.message-list:empty::before {
  content: attr(data-empty-text);
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  /* Static fallback for Safari < 16.4 — see chat.css composer-paperclip note. */
  color: #888;
  color: color-mix(in oklab, var(--fg) 55%, var(--bg-elev));
  font-style: italic;
  font-size: 0.875rem;
  font-family: var(--font-base);
  text-align: center;
  padding: 0 24px;
}

/* ── Message bubbles ── */
.message {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: var(--bubble-radius);
  box-shadow: var(--bubble-shadow);
  word-break: break-word;
  white-space: pre-wrap;
  line-height: 1.55;
}

.message[data-role="ai"] {
  align-self: flex-start;
  background: var(--bubble-ai-bg);
  color: var(--bubble-ai-fg);
  border: var(--bubble-ai-border);
}

.message[data-role="user"] {
  align-self: flex-end;
  background: var(--bubble-user-bg);
  color: var(--bubble-user-fg);
  border: var(--bubble-user-border);
}

/* ── Card-hosting bubbles: wider + no monospace bleed ──
   Inline cards (task_brief, radar_results, email_arrival, etc.)
   are wrapped in .message li. They need more horizontal space and should NOT
   inherit the bubble's monospace font (which some skins set for AI text turns).
   Rule of thumb: card messages expand to 90% and reset font to the base stack.
   user-role card bubbles (submission_card) should not show gradient — neutral bg. */
.message[data-type="task_brief_card"],
.message[data-type="profile_building_card"],
.message[data-type="profile_card"],
.message[data-type="consent_card"],
.message[data-type="submission_card"],
.message[data-type="submission_confirmation"],
.message[data-type="review_status_card"],
.message[data-type="radar_results_card"],
.message[data-type="email_arrival_card"] {
  max-width: 92%;
  padding: 0;
  background: transparent;
  border: none;
  box-shadow: none;
  /* Cards define their own bg/border/radius via inline-cards.css */
  font-family: var(--font-base);
  white-space: normal;
  line-height: normal;
}

/* Compact single-line confirmations can be a bit narrower */
.message[data-type="submission_confirmation"],
.message[data-type="review_status_card"] {
  max-width: 80%;
}

/* ── End-of-playback system row (Wave 8 P4.7) ──
   A muted italic centred row appended after the final beat. Not a chat
   bubble — visual narration. Resets every bubble style applied to .message
   so the row doesn't inherit AI/user borders or backgrounds. */
.message.message--system {
  align-self: center;
  max-width: 90%;
  background: transparent;
  color: var(--fg);
  /* Static fallback for Safari < 16.4 — see chat.css composer note. */
  color: #777;
  color: color-mix(in oklab, var(--fg) 60%, var(--bg-elev));
  border: none;
  box-shadow: none;
  padding: 8px 12px;
  font-style: italic;
  font-size: 0.8125rem;
  text-align: center;
  font-family: var(--font-base);
}

/* ── Time-skip divider (Wave 8 P4.3) ──
   Centred horizontal-rule "— 48 hours later —" between awaiting_review
   and email_arrival. Replaces the legacy plain AI bubble that just read
   "48 hours later…" — which read as the bot speaking, not a time jump. */
.time-skip-divider {
  list-style: none;
  align-self: center;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  /* Static fallback for Safari < 16.4 — see chat.css composer for context. */
  color: #777;
  color: color-mix(in oklab, var(--fg) 55%, var(--bg-elev));
  font-size: 0.8125rem;
  font-family: var(--font-base);
  font-style: italic;
  /* Span the full available width so the rules reach edge-to-edge. */
  width: 100%;
  max-width: 100%;
}
.time-skip-divider::before,
.time-skip-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}
.time-skip-divider span {
  white-space: nowrap;
  padding: 0 4px;
}

/* ── Suggestion chips ──
   Wave 8 P3.5: switched from <button disabled> to <ul><li>. The list-style
   + padding reset prevents the browser's default bullet/indent from leaking
   in. aria-label on the parent <ul> tells SR users these are illustrative. */
.chips {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 16px 4px 16px;
  margin: 0;
  align-self: flex-start;
}

.chip {
  padding: 6px 14px;
  border-radius: 100px;
  border: 1px solid var(--chip-border);
  background: var(--chip-bg);
  color: var(--chip-fg);
  font-size: 0.875rem;
  cursor: default;
  font-family: var(--font-base);
  white-space: nowrap;
  transition: background 0.15s ease;
}

/* Wave 8 P5.5: subtle background tint on hover. Chips are <li> (not
   buttons) — playback is read-only and the chip group's aria-label says
   so. The hover is deliberately quiet (~12% accent blend, no transform
   or border change) so it reads as "the cursor is over me, this is
   intentional UI" without implying clickability. cursor stays `default`
   for the same reason. */
.chip:hover {
  /* Static fallback for Safari < 16.4 — without it, color-mix is dropped
     and the chip background resolves to `initial` (transparent) on hover. */
  background: var(--chip-bg);
  background: color-mix(in oklab, var(--chip-bg) 88%, var(--accent) 12%);
}

/* ── Typing indicator ── */
.typing {
  list-style: none;
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 12px 16px;
  background: var(--bubble-ai-bg);
  border: var(--bubble-ai-border);
  border-radius: var(--bubble-radius);
  box-shadow: var(--bubble-shadow);
  min-width: 56px;
}

.typing .dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--bubble-ai-fg);
  opacity: 0.4;
  animation: dot-pulse 1.2s infinite ease-in-out;
}
.typing .dot:nth-child(1) { animation-delay: 0s; }
.typing .dot:nth-child(2) { animation-delay: 0.2s; }
.typing .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes dot-pulse {
  0%, 60%, 100% { opacity: 0.4; transform: scale(1); }
  30% { opacity: 1; transform: scale(1.3); }
}

/* ── Streaming cursor (AI bubbles during token-by-token reveal) ── */
/* Wave 8 P5.5: caret used to sit on the text baseline, which leaves a
   visible "drop" below the glyph row in mono-font skins (the ▍ extends
   below baseline). Switching to text-bottom + line-height:1 anchors the
   caret to the bottom of the line box, so it rides flush with descenders
   like 'g' and 'p' regardless of the skin's font stack. */
.message[data-streaming="true"]::after {
  content: "▍";
  display: inline-block;
  margin-left: 2px;
  vertical-align: text-bottom;
  line-height: 1;
  animation: stream-caret-blink 1s steps(2) infinite;
  opacity: 0.7;
  font-weight: normal;
}

@keyframes stream-caret-blink {
  0%, 50% { opacity: 0.7; }
  51%, 100% { opacity: 0; }
}

/* ── Composer typing state: dim send button, brighten input, show caret ── */
.composer-row[data-typing="true"] {
  /* Lift the row slightly to signal active input. */
  border-color: var(--accent);
  /* Anchor the paperclip/send to the bottom as the ghost wraps + grows the row
     (the conventional growing-composer feel — buttons stay at the baseline). */
  align-items: flex-end;
}

.composer-row[data-typing="true"] .composer-input {
  opacity: 1; /* override the :disabled 0.7 dim during typing animation */
}

/* ── Reduced motion: hide typing indicator, kill streaming caret/animation ──
   `!important` overrides the per-skin caret rules that don't always inherit
   the base @keyframes binding, and stops the dot-pulse keyframe outright. */
@media (prefers-reduced-motion: reduce) {
  .typing { display: none; }
  .typing .dot { animation: none !important; }
  .chip, .message { transition: none; }
  .message[data-streaming="true"]::after {
    display: none;
    animation: none !important;
  }
  /* No accent border-pulse and no ghost-typing visual cue. */
  .composer-row[data-typing="true"] { border-color: var(--border); }
  .composer-row[data-typing="true"] .composer-ghost { display: none; }
}

/* ── Disabled message input (v1 — kept for backward compatibility) ── */
.message-input {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-elev);
  flex-shrink: 0;
}

.message-input input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-base);
  font-size: 0.9375rem;
  background: var(--bg);
  color: var(--fg);
  opacity: 0.7;
  cursor: not-allowed;
}

.message-input button {
  padding: 8px 18px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-base);
  font-size: 0.9375rem;
  opacity: 0.7;
  cursor: not-allowed;
}

/* ── v2 Composer (paperclip + input + send; visible but disabled in playback) ── */
.composer {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 14px 12px;
  border-top: 1px solid var(--border);
  background: var(--bg-elev);
  flex-shrink: 0;
}

/* Pill-shaped attachment previews above the row (hidden until files are attached) */
.composer-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.composer-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--bubble-radius);
  padding: 4px 6px 4px 10px;
  position: relative; /* anchors .composer-ghost overlay during user-typing sim */
}

/* Ghost typing layer — the user-typing simulation writes here, NOT into the
   disabled <input>. Visible only while [data-typing="true"]; otherwise hidden
   so it never interferes with the input's placeholder.
   aria-hidden="true" is set in JS — SR users never hear this stream. */
.composer-ghost {
  /* In-flow (NOT absolute): while [data-typing], the ghost takes the input's
     slot in the flex row so a long simulated message WRAPS onto multiple lines
     and grows the composer height — instead of being clipped to one line with
     an ellipsis. Hidden otherwise so it never interferes with the placeholder. */
  display: none;
  flex: 1 1 auto;
  min-width: 0;
  font-family: var(--font-base);
  font-size: 0.9375rem;
  line-height: 1.45;
  color: var(--fg);
  pointer-events: none;
  padding: 6px 4px; /* match .composer-input padding so the text aligns */
  white-space: pre-wrap;   /* wrap instead of single-line clip */
  overflow-wrap: anywhere; /* also break pathological unbroken strings (URLs) */
  max-height: 40vh;        /* a very long message scrolls rather than eating the viewport */
  overflow-y: auto;
}

.composer-row[data-typing="true"] .composer-ghost {
  display: block;
}

/* While the ghost is active, REPLACE the single-line input with the in-flow
   wrapping ghost above. display:none drops the input from the flex row so only
   the ghost occupies the text slot (and the row can grow with wrapped text). */
.composer-row[data-typing="true"] .composer-input {
  display: none;
}

/* Paperclip button.
   NOTE: opacity-based dims (was 0.45) failed WCAG 1.4.11 non-text contrast
   (1.16–1.36) on multiple skins. Replaced with color-mix to produce a solid
   muted colour at full opacity — same visual "disabled" intent, real contrast. */
.composer-paperclip {
  flex-shrink: 0;
  background: transparent;
  border: none;
  padding: 4px;
  font-size: 1.125rem;
  cursor: not-allowed;
  /* Static fallback for Safari < 16.4 (color-mix shipped Oct 2022).
     Older browsers ignore the unknown color-mix() and use this hex;
     modern browsers cascade-override with the per-skin oklab mix. */
  color: #777;
  color: color-mix(in oklab, var(--fg) 50%, var(--bg-elev));
  border-radius: var(--radius);
  line-height: 1;
  /* WCAG 2.5.5: min 44×44 touch target. The icon glyph stays at its
     1.125rem size; the box just grows and centers it. */
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Main text input */
.composer-input {
  flex: 1;
  border: none;
  background: transparent;
  font-family: var(--font-base);
  font-size: 0.9375rem;
  color: var(--fg);
  padding: 6px 4px;
  outline: none;
  min-width: 0;
}

.composer-input::placeholder {
  /* Static fallback for Safari < 16.4 — see .composer-paperclip note above. */
  color: #888;
  color: color-mix(in oklab, var(--fg) 50%, var(--bg-elev));
}

/* Disabled input — keep cursor:not-allowed as a meaningful affordance;
   drop opacity in favour of a muted-but-solid foreground. */
.composer-input:disabled {
  cursor: not-allowed;
  /* Static fallback for Safari < 16.4 — see .composer-paperclip note above. */
  color: #555;
  color: color-mix(in oklab, var(--fg) 75%, var(--bg-elev));
}

/* Send button */
.composer-send {
  flex-shrink: 0;
  background: var(--accent);
  color: var(--bg-elev);
  border: none;
  border-radius: var(--bubble-radius);
  /* WCAG 2.5.5: min 44×44 touch target (was a 34×34 box). The send glyph
     stays at 0.9375rem and the flex centering keeps it dead-centre. */
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9375rem;
  cursor: not-allowed;
  /* opacity dim removed — was 0.45 and washed the button to ~1.2:1 contrast.
     Each skin paints its own --accent at full opacity. */
}

/* ── Concept end-card (item F) ──────────────────────────────────────────────
   A closing frame for the team/angel audience: a concept note + a quiet
   "Talk to us" mailto link. Sits in the message-list flow immediately before
   the .message--system end-row (which stays the literal last child).
   The <a> is styled as a quiet button — 44px min touch target, visible focus,
   NOT a sales CTA, NOT a lead-capture form. */
.concept-cta {
  align-self: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  max-width: 480px;
  width: 100%;
  box-sizing: border-box;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--bubble-radius);
  text-align: center;
  font-family: var(--font-base);
}

.concept-cta__line {
  margin: 0;
  font-size: 0.875rem;
  /* Static fallback for Safari < 16.4 */
  color: #777;
  color: color-mix(in oklab, var(--fg) 65%, var(--bg-elev));
  line-height: 1.5;
}

.concept-cta__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  /* WCAG 2.5.5: ≥ 44px touch target */
  min-height: 44px;
  padding: 10px 22px;
  border-radius: 100px;
  border: 1px solid var(--border);
  background: var(--bg);
  /* Static fallback for Safari < 16.4 */
  color: #555;
  color: color-mix(in oklab, var(--fg) 80%, var(--bg-elev));
  font-family: var(--font-base);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
  cursor: pointer;
}

.concept-cta__btn:hover {
  background: var(--bg-elev);
  border-color: var(--accent);
  /* Static fallback for Safari < 16.4 */
  color: #333;
  color: color-mix(in oklab, var(--fg) 95%, var(--bg-elev));
}

.concept-cta__btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* End-of-journey handoff: a prominent line + a row with the quiz CTA (primary) and
   the "Talk to us" link (secondary). */
.concept-cta__quizline {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.4;
  color: var(--fg);
}
.concept-cta__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}
/* Primary action - take the snapshot yourself. Accent fill stands out next to the
   quiet outline "Talk to us". */
.concept-cta__btn--quiz {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.concept-cta__btn--quiz:hover {
  background: var(--accent);
  border-color: var(--accent);
  filter: brightness(1.06);
  color: #fff;
}

@media (prefers-reduced-motion: reduce) {
  .concept-cta__btn { transition: none; }
}
