/* ----------------------------------------------------------------------------
   chat.css — The conversation itself: the centred message column, user/assistant
   bubbles, the empty-chat greeting, the thinking indicator, and attachments
   rendered inside a message.
   Slice 9 of 16 (see css/tokens.css for the full load order).
   ------------------------------------------------------------------------- */
/* ------------------------------------------------------------ chat */
/* The conversation stays a centred column (max-width + margin:auto from .page).
   The context rail (.chat-rail) is taken out of flow and floated into the right
   gutter, so it never shifts the chat off-centre — it only appears when the
   gutter is actually wide enough to hold it (see the min-width query below).
   position:static so the rail's offset parent becomes .app-main, not this box. */
.chat-page {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  max-width: 1040px;
  padding-bottom: 18px;
  position: static;
  transition: padding-left 0.25s cubic-bezier(0.16, 1, 0.3, 1), padding-right 0.25s cubic-bezier(0.16, 1, 0.3, 1), max-width 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Prevent overlap when Files panel is open: reduce left gap and reserve right space for Clear chat button */
@media (min-width: 1200px) {
  .chat-page.files-open {
    padding-left: 295px;
    padding-right: 140px;
    max-width: 1480px;
  }
}

@media (min-width: 980px) and (max-width: 1199px) {
  .chat-page.files-open {
    padding-left: 285px;
    padding-right: 135px;
    max-width: 100%;
  }
}

.chat-col {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  min-height: 0;
}

.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  /* Stable scrollbar gutter; modest top padding — Files / Clear / rail sit
     fixed on the row above and never reflow this column. */
  scrollbar-gutter: stable both-edges;
  padding: 18px 16px 18px;
}

/* Empty chat: greeting and composer travel together, vertically centred, so the
   input sits directly under the suggestion chips. `flex: 0 1 auto` lets the
   greeting still shrink/scroll on a short viewport. app.js runs a FLIP to slide
   the composer down to the bottom once the first message is sent. */
/* The 30px top padding on .chat-page exists for the Library page's heading.
   The empty chat has no heading, so there it only pushes the greeting down. */
.chat-page.chat-empty {
  padding-top: 18px;
}

.chat-page.chat-empty .chat-col {
  justify-content: center;
  /* Optical lift. justify-content centres the greeting+composer group in the
     column, but the column starts below a fixed ~57px header — so a group at
     the column's mathematical centre still reads as sitting low on screen.
     Pulling the bottom in nudges it up to roughly the VIEWPORT centre.
     Viewport-relative so short screens give the greeting its space back rather
     than being cropped by a fixed offset; capped so it doesn't run away on
     very tall ones.
     (Anchoring the COMPOSER itself to the exact centre was tried and reverted
     — it left the greeting crowding the header and a large dead area below the
     input. Centring the group as a whole is the intended look.) */
  padding-bottom: clamp(0px, 7vh, 60px);
}

.chat-page.chat-empty .chat-messages {
  flex: 0 1 auto;
  padding-top: 8px;
}

.chat-hello {
  margin: auto;
  text-align: center;
  padding: 30px 10px;
  transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  max-height: 500px;
}

.chat-hello.fade-out {
  opacity: 0;
  transform: scale(0.95) translateY(-24px);
  max-height: 0;
  padding: 0 10px;
  margin: 0;
  overflow: hidden;
}

.hello-gradient {
  font-size: clamp(30px, 6vw, 46px);
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0 0 2px;
  background: var(--grad);
  background-size: 220% 220%;
  background-position: var(--gx, 50%) 50%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: hue-rotate(var(--hue, 0deg)) saturate(var(--sat, 1));
  will-change: background-position, filter;
}

.hello-sub {
  font-size: clamp(17px, 3vw, 22px);
  color: var(--muted);
  margin: 0;
  font-weight: 400;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 28px;
}

.suggestion {
  height: auto;
  background: var(--surface);
  border: none;
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: 14px;
  color: var(--text);
  max-width: 230px;
  text-align: left;
  white-space: normal;
  line-height: 1.4;
}

.suggestion:hover {
  background: var(--surface-2);
}

.msg {
  max-width: 88%;
  position: relative;
  animation: msg-entry 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes msg-entry {
  from {
    opacity: 0;
    transform: translateY(16px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.msg.user {
  align-self: flex-end;
}

.msg.user .msg-body {
  background: var(--surface-3);
  color: var(--text);
  border-radius: 20px 20px 6px 20px;
  padding: 11px 17px;
  overflow-wrap: anywhere;
}

.msg.assistant {
  align-self: flex-start;
  width: 88%;
  padding-left: 32px;
}

.msg-avatar {
  position: absolute;
  left: 0;
  top: 12px;
  width: 20px;
  height: 20px;
  object-fit: contain;
}

/* .pulsing is a marker class: the opacity pulse itself is driven by JS (see
   appendAssistantLive in js/app.js) on the dash field's cadence. As an
   infinite CSS animation it ticked at the display's refresh rate and forced
   full-page composites at 120Hz on ProMotion for as long as a reply streamed. */
.msg.assistant .msg-body {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px 20px 20px 20px;
  padding: 14px 18px;
  box-shadow: var(--shadow-soft);
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.msg-body.error-bubble {
  color: var(--danger-text);
  border-color: color-mix(in srgb, var(--danger-text) 40%, transparent);
}

/* "answer may be incomplete" note under a cut-short assistant reply */
.msg-warning {
  margin-top: 6px;
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--danger-text);
  opacity: 0.85;
}

/* resume a cut-short enumeration (renderTruncationNote) */
.continue-btn {
  margin-left: 8px;
  padding: 2px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--danger-text);
  background: transparent;
  border: 1px solid color-mix(in srgb, var(--danger-text) 45%, transparent);
  border-radius: 999px;
  cursor: pointer;
  vertical-align: baseline;
}
.continue-btn:hover {
  background: color-mix(in srgb, var(--danger-text) 12%, transparent);
}

.msg-copy {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  margin-top: 4px;
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  opacity: 0.55;
  transition: opacity 0.15s ease, color 0.15s ease, background-color 0.15s ease;
}

.msg-copy svg {
  width: 15px;
  height: 15px;
}

.msg-copy:hover:not(:disabled) {
  opacity: 1;
  color: var(--text);
  background: var(--surface-2);
  border: none;
}

.msg-copy:focus-visible {
  opacity: 1;
  outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent);
  outline-offset: 2px;
}

.msg-copy.copied {
  opacity: 1;
  color: var(--accent);
}

.msg.user .msg-copy {
  display: flex;
  margin-left: auto;
}

/* ---- thinking indicator ----
   .msg.assistant is width:88%, which left a near-empty full-width bubble while
   waiting. Shrink to content until real text arrives (JS drops .is-thinking). */
.msg.assistant.is-thinking {
  width: auto;
}

.msg.assistant.is-thinking .msg-body {
  display: inline-flex;
  align-items: center;
  padding: 12px 16px;
  white-space: nowrap;
}

.thinking {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

/* the bounce is driven by JS (js/app.js), same reasoning as .msg-avatar.pulsing */
.typing i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.3;
}

.thinking-phase {
  font-size: 13px;
  color: var(--muted);
  opacity: 1;
  transition: opacity 0.14s ease;
}

.thinking-phase:empty {
  display: none;
}

.thinking-phase.fading {
  opacity: 0;
}

/* (reduced-motion handling for the typing dots / avatar pulse lives in the JS
   driver: opacity-only, at a slower cadence) */
/* Attached images sit below the bubble; the wrapper keeps them aligned with
   the message side and stops a tall photo from dominating the thread. */
/* flex-start, not the default stretch: otherwise a short image's box is pulled
   to the tallest sibling's height and the picture letterboxes inside it. */
.chat-imgs {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 8px;
  margin-top: 8px;
}

.msg.user .chat-imgs {
  justify-content: flex-end;
}

.chat-img {
  max-width: min(240px, 100%);
  max-height: 260px;
  width: auto;
  height: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  display: block;
  object-fit: contain;
}

.chip-thumb {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  object-fit: cover;
  display: block;
}

.attach-chip,
.pending-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 20px;
  margin: 6px 6px 0 0;
}

.chip-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chip-icon {
  display: inline-flex;
  align-items: center;
}

.chip-icon svg {
  width: 13px;
  height: 13px;
  display: block;
}

.chip-remove {
  height: auto;
  width: auto;
  padding: 0;
  border: none;
  background: none;
  color: var(--muted);
}

.chip-remove svg {
  width: 12px;
  height: 12px;
  display: block;
}

.chip-remove:hover {
  color: var(--danger-text);
  border: none;
  background: none;
}

/* a chat attachment still being AI-distilled — dashed border + breathing
   label until the summary lands (see app.js stageHugeChatFile) */
.pending-chip.staging {
  border-style: dashed;
}

.pending-chip.staging .chip-label {
  animation: chip-staging 1.6s ease-in-out infinite;
}

@keyframes chip-staging {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

@media (prefers-reduced-motion: reduce) {
  .pending-chip.staging .chip-label {
    animation: none;
    opacity: 0.7;
  }
}

