/* ==========================================================================
   The chat (story #111, 03-Design/chat.md): the conversation, answers formatted as they stream, code coloured by
   language. Plain CSS on the theme's tokens, so light and dark follow the theme; nothing here is inline (CSP).
   ========================================================================== */

.chat {
  margin: 0 auto;
  display: flex;
  min-height: calc(100vh - var(--topbar-h));
  max-width: 48rem;
  flex-direction: column;
  padding: 1.25rem 1rem 1rem;
}

.chat-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

/* D198: the cited document beside the conversation, from the top of the window with its header level with the top bar (no
   empty strip above it, owner's test); on a narrow screen it covers the page, with its close at hand. */
.chat-viewer {
  position: fixed;
  z-index: 40;
  top: 0;
  right: 0;
  bottom: 0;
  display: flex;
  width: min(46vw, 56rem);
  flex-direction: column;
  border-left: 1px solid rgb(var(--s-line));
  background: rgb(var(--s-surface));
  box-shadow: -12px 0 32px rgb(0 0 0 / .18);
}
.chat-viewer-head { display: flex; min-height: var(--topbar-h); align-items: center; gap: .5rem; padding: .5rem .75rem; border-bottom: 1px solid rgb(var(--s-line)); }
.chat-viewer-title { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; font-size: 14px; }
.chat-viewer-frame { width: 100%; flex: 1; border: 0; background: rgb(var(--s-bg)); }
.chat-viewer-picture { display: grid; flex: 1; min-height: 0; place-items: center; overflow: auto; padding: 1rem; background: rgb(var(--s-bg)); }
.chat-viewer-picture img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: .5rem; }
@media (min-width: 1100px) { body.has-chat-viewer .app-main { padding-right: min(46vw, 56rem); } }
@media (max-width: 1099px) { .chat-viewer { left: 0; width: auto; border-left: 0; } }

/* D273: the persona and model pickers sit in the composer's toolbar as text with a chevron, not as bordered boxes, as in
   Claude Desktop. They stay native selects, so the keyboard and the screen reader work as before; the chevron is drawn by
   two gradients (no picture, CSP). A long name is cut, never the row: they shrink before the icons do. */
.chat-picker {
  appearance: none; -webkit-appearance: none;
  flex: 0 1 auto; min-width: 2.75rem; max-width: 15rem; height: 28px; field-sizing: content;
  padding: 0 1.15rem 0 .5rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  border: 0; border-radius: 8px;
  background-color: transparent;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - .6rem) 52%, calc(100% - .35rem) 52%;
  background-size: .25rem .25rem, .25rem .25rem;
  background-repeat: no-repeat;
  color: rgb(var(--s-muted)); font: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer;
}
.chat-picker:hover:not(:disabled) { color: rgb(var(--s-fg)); background-color: rgb(var(--s-surface-2)); }
.chat-picker:focus-visible { outline: 2px solid rgb(var(--s-brand)); outline-offset: 1px; }
.chat-picker:disabled { opacity: .5; cursor: default; } /* greyed, as the browser greyed the boxed select */
.chat-picker option { color: rgb(var(--s-fg)); background: rgb(var(--s-surface)); }
.chat-status { margin-left: auto; font-size: 12px; font-weight: 600; color: rgb(var(--s-warn)); }
.chat-status:empty { display: none; }
/* Review F1 (#206): the status line's Reconnect, while the connection is gone for good. */
.chat-status-action {
  margin-left: .35rem; padding: .1rem .55rem; border-radius: 99px; font: inherit; cursor: pointer;
  color: rgb(var(--s-brand)); background: rgb(var(--s-brand) / .1); border: 1px solid rgb(var(--s-brand) / .35);
}
.chat-status-action:hover { background: rgb(var(--s-brand) / .18); }
.chat-status-action:disabled { opacity: .6; cursor: default; }

/* Before the first message (as in Claude and ChatGPT): the greeting, the box in the middle, the starters under it. */
.chat.is-empty { justify-content: center; }

/* Once the conversation runs, the box is the page's last thing: where it rests at the very bottom is where it floats, so it
   does not jump when the reader reaches the end (owner's test). */
.chat:not(.is-empty) { padding-bottom: 0; }
.chat.is-empty .chat-bar { position: absolute; top: calc(var(--topbar-h) + 1.25rem); }
.chat.is-empty .chat-log { display: none; }
.chat.is-empty .chat-composer { position: static; margin: 1.5rem 0 0; padding: 0; background: none; backdrop-filter: none; -webkit-backdrop-filter: none; }
.chat.is-empty .chat-composer::before { display: none; }

.chat-hero { display: flex; flex-direction: column; align-items: center; text-align: center; }

/* D123: the SophIA logo above the greeting, at the size of an app icon. */
.chat-logo {
  display: grid;
  place-items: center;
  width: 3.5rem;
  height: 3.5rem;
  margin-bottom: 1rem;
  border-radius: 1rem;
  background: rgb(var(--s-brand));
  color: rgb(var(--s-brand-fg));
  box-shadow: var(--shadow-card);
}

.chat-logo-mark { width: 2rem; height: 2rem; }
.chat-greeting { font-size: clamp(1.9rem, 4vw, 2.5rem); font-weight: 800; line-height: 1.15; letter-spacing: -0.02em; text-wrap: balance; }
.chat-no-persona { margin-top: 0.75rem; font-size: 14px; color: rgb(var(--s-muted)); }

.chat-starters {
  margin-top: 1rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
}


.chat-starter {
  border: 1px solid rgb(var(--s-line));
  border-radius: 999px;
  background: rgb(var(--s-surface));
  padding: 0.45rem 0.95rem;
  font-size: 13px;
  font-weight: 600;
  color: rgb(var(--s-fg));
  transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease);
}

.chat-starter:hover { background: rgb(var(--s-surface-2)); border-color: rgb(var(--s-muted) / 0.5); }
.chat-starter:focus-visible { outline: 2px solid rgb(var(--s-brand)); outline-offset: 2px; }

.chat-log {
  flex: 1;
  list-style: none;
  margin: 1.5rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.chat-message { display: flex; flex-direction: column; gap: 0.35rem; }
.chat-user { align-items: flex-end; }

.chat-bubble {
  max-width: 85%;
  border-radius: var(--r-lg);
  background: rgb(var(--s-surface-2));
  padding: 0.65rem 0.95rem;
}

.chat-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; line-height: 1.6; }
.chat-user.is-pending .chat-bubble { opacity: 0.65; }

.chat-thinking { font-size: 14px; color: rgb(var(--s-muted)); }

/* D137: a skill the person switches on beside the question box; what a skill is doing; the steps under the answer. */
.chat-skill-buttons { display: flex; flex-wrap: wrap; gap: 0.375rem; }
.chat-skill { display: inline-flex; align-items: center; gap: 0.375rem; padding: 0.3rem 0.65rem; border: 1px solid rgb(var(--s-line)); border-radius: 999px; font-size: 13px; font-weight: 600; color: rgb(var(--s-muted)); background: transparent; }
.chat-skill svg { width: 1rem; height: 1rem; }
.chat-skill:hover { color: rgb(var(--s-fg)); background: rgb(var(--s-surface-2)); }
.chat-skill[aria-pressed="true"] { color: rgb(var(--s-brand)); border-color: rgb(var(--s-brand) / .45); background: rgb(var(--s-brand) / .08); }
/* #133 (D271, D273): "Ask my files" beside the attach button, an icon that stays pressed in the brand's tint while on, and
   stays out of sight until the hub offers it. */
.chat-my-files[aria-pressed="true"] { color: rgb(var(--s-brand)); background: rgb(var(--s-brand) / .12); }
.chat-my-files[aria-pressed="true"]:hover { color: rgb(var(--s-brand)); background: rgb(var(--s-brand) / .18); }
.chat-skill:focus-visible { outline: 2px solid rgb(var(--s-brand)); outline-offset: 1px; }
.chat-tool-status { font-size: 14px; color: rgb(var(--s-muted)); }
.chat-assistant.is-running .chat-tool-status:not([hidden]) { animation: chat-pulse 1.4s var(--ease) infinite; }
/* #116, D140: a citation in the text, the product cards, the pictures and the sources under the answer. */
.chat-cite { display: inline-flex; align-items: center; gap: 0.2rem; margin: 0 0.1rem; padding: 0 0.35rem; border: 1px solid rgb(var(--s-line)); border-radius: 999px; background: rgb(var(--s-brand) / .06); color: rgb(var(--s-muted)); font-size: 11.5px; line-height: 1.55; text-decoration: none; vertical-align: baseline; }
.chat-cite:hover { color: rgb(var(--s-fg)); border-color: rgb(var(--s-brand) / .45); }
.chat-cite img { width: 12px; height: 12px; border-radius: 2px; }
.chat-products { margin-top: 0.75rem; display: grid; gap: 0.6rem; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.chat-product { display: flex; flex-direction: column; gap: 0.35rem; padding: 0.6rem; border: 1px solid rgb(var(--s-line)); border-radius: 12px; background: rgb(var(--s-surface)); }
.chat-product a { font-weight: 600; font-size: 14px; color: rgb(var(--s-fg)); text-decoration: none; }
.chat-product a:hover { color: rgb(var(--s-brand)); }
.chat-product-shot { width: 100%; height: 120px; object-fit: contain; background: rgb(var(--s-surface-2)); border-radius: 8px; }
.chat-product-price { font-weight: 700; }
.chat-product-meta { font-size: 12.5px; color: rgb(var(--s-muted)); display: flex; flex-wrap: wrap; gap: 0.35rem; }
.chat-product-more { display: flex; gap: 0.3rem; flex-wrap: wrap; }
.chat-product-more img { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; border: 1px solid rgb(var(--s-line)); }
.chat-pictures { margin-top: 0.75rem; display: flex; gap: 0.4rem; flex-wrap: wrap; }
.chat-pictures a { display: block; }
.chat-pictures img { width: 92px; height: 92px; object-fit: cover; border-radius: 8px; border: 1px solid rgb(var(--s-line)); }
/* #141: a picture where the answer explains it. */
.chat-figure { margin: 0.6rem 0; display: grid; gap: 0.3rem; justify-items: start; }
/* Whatever a model writes, a picture never grows a table's rows; a chip's icon is small enough to stay. */
.chat-markdown table .chat-figure { display: none; }
.chat-markdown table img:not(.chat-cite img) { max-width: 2rem; max-height: 2rem; }
.chat-markdown table { min-width: min(48rem, 100%); }
.chat-figure img { max-width: min(100%, 28rem); max-height: 20rem; object-fit: contain; border: 1px solid rgb(var(--s-line)); border-radius: 10px; background: rgb(var(--s-surface-2)); cursor: zoom-in; }
.chat-figure figcaption { font-size: 12.5px; color: rgb(var(--s-muted)); }
/* H1, #204 (D238): an image the answer writes waits for the whole answer, then shows only from an address its sources hold; any other reads as its words and address. */
.chat-image { max-width: min(100%, 28rem); max-height: 20rem; object-fit: contain; border: 1px solid rgb(var(--s-line)); border-radius: 10px; }
.chat-image-waiting { display: inline-block; padding: 0.15rem 0.5rem; border: 1px dashed rgb(var(--s-line)); border-radius: 6px; font-size: 12.5px; color: rgb(var(--s-muted)); }
.chat-image-refused { font-size: 12.5px; color: rgb(var(--s-muted)); overflow-wrap: anywhere; }
.chat-gallery { width: min(92vw, 60rem); max-width: none; padding: 0; border: 1px solid rgb(var(--s-line)); border-radius: 14px; background: rgb(var(--s-surface)); color: rgb(var(--s-fg)); }
.chat-gallery::backdrop { background: rgb(0 0 0 / .6); }
.chat-gallery figure { margin: 0; display: grid; gap: 0.5rem; padding: 1rem; }
.chat-gallery img { width: 100%; max-height: 70vh; object-fit: contain; background: rgb(var(--s-surface-2)); border-radius: 10px; }
.chat-gallery figcaption { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.5rem; font-size: 13px; color: rgb(var(--s-muted)); }
.chat-gallery figcaption a { color: rgb(var(--s-brand)); }
.chat-gallery-count { margin-left: auto; font-variant-numeric: tabular-nums; }
.chat-gallery-move, .chat-gallery-close { position: absolute; border: 1px solid rgb(var(--s-line)); border-radius: 999px; background: rgb(var(--s-surface)); color: rgb(var(--s-fg)); width: 2.25rem; height: 2.25rem; font-size: 20px; line-height: 1; cursor: pointer; }
.chat-gallery-move { top: 50%; transform: translateY(-50%); left: 0.5rem; }
.chat-gallery-move.is-next { left: auto; right: 0.5rem; }
.chat-gallery-close { top: 0.5rem; right: 0.5rem; font-size: 18px; }
.chat-gallery-move:hover, .chat-gallery-close:hover { border-color: rgb(var(--s-brand) / .45); color: rgb(var(--s-brand)); }
.chat-pictures img, .chat-product-more img { cursor: zoom-in; }
.chat-sources { margin-top: 0.6rem; font-size: 13px; color: rgb(var(--s-muted)); }
.chat-sources summary { cursor: pointer; width: fit-content; font-weight: 600; }
.chat-sources summary:hover { color: rgb(var(--s-fg)); }
.chat-sources ol { margin: 0.35rem 0 0; padding-left: 1.25rem; display: grid; gap: 0.25rem; }
.chat-sources a { color: inherit; text-decoration: none; display: inline-flex; align-items: center; gap: 0.35rem; }
.chat-sources a:hover { color: rgb(var(--s-brand)); }
.chat-sources img { width: 14px; height: 14px; border-radius: 3px; }
/* A live result among the sources (#131): its title as words, a small arrow that opens it, its words as they were written. */
.chat-cite.is-live svg { width: 10px; height: 10px; flex: none; }
.chat-live { padding: 0.15rem 0 0.35rem; }
.chat-live-head { display: flex; align-items: flex-start; gap: 0.5rem; }
.chat-live-title { min-width: 0; color: rgb(var(--s-fg)); font-weight: 600; overflow-wrap: anywhere; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; }
.chat-sources a.chat-live-open { flex: none; display: inline-grid; place-items: center; width: 1.45rem; height: 1.45rem; margin-top: -0.05rem; border: 1px solid rgb(var(--s-line)); border-radius: 0.45rem; color: rgb(var(--s-muted)); }
.chat-sources a.chat-live-open:hover, .chat-sources a.chat-live-open:focus-visible { color: rgb(var(--s-brand)); border-color: rgb(var(--s-brand) / .55); background: rgb(var(--s-brand) / .08); }
.chat-live-open svg { width: 13px; height: 13px; }
.chat-live-site { display: block; font-size: 12px; }
.chat-live-text { margin: 0.4rem 0 0; padding: 0.6rem 0.75rem; max-height: 15rem; overflow: auto; border: 1px solid rgb(var(--s-line)); border-radius: var(--r-md); background: rgb(var(--s-surface)); color: rgb(var(--s-fg)); font: 12px/1.55 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; tab-size: 2; }
.chat-steps { margin-top: 0.5rem; font-size: 13px; color: rgb(var(--s-muted)); }
.chat-steps summary { cursor: pointer; width: fit-content; font-weight: 600; }
.chat-steps summary:hover { color: rgb(var(--s-fg)); }
.chat-steps ol { margin: 0.35rem 0 0; padding-left: 1.25rem; display: grid; gap: 0.2rem; list-style: decimal; }
.chat-steps li.is-failed { color: rgb(var(--s-err)); }
/* #209 (D297): a step that ran code shows the code, highlighted as the chat's code blocks are, and what it printed. */
/* #209 (the owner's walk, 2026-10-19): a long line of code or output scrolls inside its box, never past the answer's column. */
.chat-steps ol { grid-template-columns: minmax(0, 1fr); }
.chat-steps li.has-code { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.25rem; min-width: 0; }
.chat-step-code { color: rgb(var(--s-fg)); min-width: 0; max-width: 100%; }
.chat-step-code > summary { font-weight: 500; color: rgb(var(--s-muted)); }
.chat-step-code .chat-code { margin: 0.35rem 0 0; padding: 0.6rem 0.8rem; max-height: 22rem; overflow: auto; border: 1px solid rgb(var(--s-line)); border-radius: var(--r-md); background: rgb(var(--s-surface)); font: 12px/1.55 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; white-space: pre; tab-size: 4; }
.chat-step-output-label { margin: 0.45rem 0 0.15rem; font-size: 12px; font-weight: 600; color: rgb(var(--s-muted)); }
.chat-step-output { margin: 0; padding: 0.55rem 0.75rem; max-height: 15rem; overflow: auto; border: 1px solid rgb(var(--s-line)); border-radius: var(--r-md); background: rgb(var(--s-surface)); font: 12px/1.55 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
@media (prefers-reduced-motion: reduce) {
  .chat-assistant.is-running .chat-tool-status:not([hidden]) { animation: none; }
}
.chat-assistant.is-running .chat-thinking:not([hidden]) { animation: chat-pulse 1.4s var(--ease) infinite; }

@keyframes chat-pulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .chat-assistant.is-running .chat-thinking:not([hidden]) { animation: none; }
}

.chat-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.125rem; }

/* D127: the actions are icons, shown when the reader points at or tabs into the message, and always on the last answer and
   on touch screens, which have no hover (as in ChatGPT and Claude). */
.chat-message > .chat-actions { opacity: 0; transition: opacity 0.15s var(--ease); }
.chat-message:hover > .chat-actions,
.chat-message:focus-within > .chat-actions,
.chat-assistant:last-child > .chat-actions { opacity: 1; }

@media (hover: none) {
  .chat-message > .chat-actions { opacity: 1; }
}

.chat-icon-btn {
  display: inline-grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: var(--r-sm);
  color: rgb(var(--s-muted));
}

.chat-icon-btn svg { width: 1.05rem; height: 1.05rem; }
.chat-icon-btn:hover { background: rgb(var(--s-surface-2)); color: rgb(var(--s-fg)); }
.chat-icon-btn:focus-visible { outline: 2px solid rgb(var(--s-brand)); outline-offset: 1px; }
.chat-actions .chat-model { margin: 0 0 0 0.5rem; }
.chat-model { margin-right: 0.5rem; font-size: 12px; font-weight: 600; color: rgb(var(--s-muted)); }
.chat-notes { font-size: 12px; color: rgb(var(--s-muted)); }

.chat-problem {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  border-radius: var(--r-md);
  border: 1px solid rgb(var(--s-err) / 0.35);
  background: rgb(var(--s-err) / 0.08);
  padding: 0.5rem 0.75rem;
  font-size: 14px;
  color: rgb(var(--s-err));
}


.chat-editor { width: 100%; max-width: 85%; display: flex; flex-direction: column; gap: 0.5rem; }
.chat-editor textarea { width: 100%; }

/* While a question is edited, the editor takes its place: its bubble and its Copy and Edit go away. */
.chat-message.is-editing > .chat-bubble,
.chat-message.is-editing > .chat-actions { display: none; }
.chat-editor .chat-actions { justify-content: flex-end; }

/* ---------- long conversations (D126) ---------- */

.chat-earlier {
  align-self: center;
  margin-top: 1.25rem;
  border: 1px solid rgb(var(--s-line));
  border-radius: 999px;
  background: rgb(var(--s-surface));
  padding: 0.35rem 0.9rem;
  font-size: 13px;
  font-weight: 600;
  color: rgb(var(--s-muted));
}

.chat-earlier:hover { color: rgb(var(--s-fg)); }

.chat-divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 12px;
  font-weight: 600;
  color: rgb(var(--s-muted));
}

.chat-divider::before,
.chat-divider::after { content: ""; flex: 1; border-top: 1px solid rgb(var(--s-line)); }

.chat-full {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  border: 1px solid rgb(var(--s-line));
  border-radius: var(--r-lg);
  background: rgb(var(--s-surface));
  padding: 0.9rem 1rem;
  font-size: 14px;
}


/* #80 (D277): a conversation that can only be read offers nothing to write in it again. */
.is-read-only [data-chat-edit], .is-read-only [data-chat-regenerate] { display: none; }

/* D273: one rounded card, as Claude Desktop's composer: 16 px on all four corners, lifted off the bottom edge, with a
   shadow; the text on top with no border of its own, the staged files under it, then the toolbar. */
.chat-box {
  padding: .4rem .5rem .45rem;
  border-radius: 16px;
  box-shadow: 0 1px 2px rgb(42 43 39 / .06), 0 6px 24px -6px rgb(42 43 39 / .16);
}
.dark .chat-box { box-shadow: 0 1px 2px rgb(0 0 0 / .4), 0 8px 28px -8px rgb(0 0 0 / .65); }
.chat-box > textarea { padding: .5rem .55rem .35rem; font-size: 15px; }
.chat-box .chat-attachments { margin: 0 0 .3rem; padding: .25rem .3rem 0; }

/* One row of small controls in a 13 px font: 28 px icons and the pickers on the left, send (32 px) on the right. It never
   wraps: on a phone the pickers and the skills' names give way first, then nothing else is needed. */
.chat-toolbar { display: flex; flex-wrap: nowrap; align-items: center; gap: .25rem; min-width: 0; padding: 0 .1rem; font-size: 13px; }
.chat-toolbar > .chat-icon-btn { flex: none; width: 28px; height: 28px; border-radius: 8px; }
.chat-toolbar > .chat-icon-btn svg { width: 1.05rem; height: 1.05rem; }
.chat-toolbar > .flex-1 { flex: 1 1 0; min-width: .25rem; }
.chat-toolbar .chat-skill-buttons { flex: 0 1 auto; flex-wrap: nowrap; min-width: 0; overflow: hidden; gap: .25rem; }
.chat-toolbar .chat-skill { flex: none; height: 28px; padding: 0 .55rem; gap: .3rem; font-size: 13px; }
.chat-toolbar [data-chat-stop] { flex: none; height: 28px; padding: 0 .6rem; font-size: 13px; }
.chat-toolbar [data-chat-send] { flex: none; width: 32px; height: 32px; border-radius: 10px; }
@media (max-width: 480px) {
  .chat-toolbar .chat-skill-buttons { flex: none; }
  .chat-toolbar .chat-skill { padding: 0; width: 28px; justify-content: center; }
  .chat-toolbar .chat-skill [data-skill-name] { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .chat-toolbar [data-chat-stop] { width: 28px; padding: 0; font-size: 0; gap: 0; }
}

/* The note inside the card, under a rule inset from both edges (owner, 2026-09-22), now small and close (D273). */
.chat-note {
  margin: 0.4rem 0.5rem 0;
  padding-top: 0.4rem;
  border-top: 1px solid rgb(var(--s-line));
  text-align: center;
  font-size: 11.5px;
  font-weight: 600;
  color: rgb(var(--s-muted));
}

/* D273: sticky over the conversation on an opaque band of the page's own colour that reaches the bottom edge, so the
   messages scroll behind it and never show through; the card rests 14 px above the edge, and a short fade above the band
   lets the last lines go under it softly. The band spans the column's padding too. Over a picture (#119) a flat band
   would be a strip of colour (owner, 2026-09-22): there it is the veil's own bottom step, blurred, which reads as the
   veil and still hides the text behind it. */
.chat-composer {
  position: sticky;
  bottom: 0;
  z-index: 5;
  margin: 2rem -1rem 0;
  padding: 0 1rem 14px;
  background: rgb(var(--s-bg));
}
.chat-composer::before {
  content: ""; position: absolute; left: 0; right: 0; bottom: 100%; height: 1.25rem; pointer-events: none;
  background: linear-gradient(to bottom, rgb(var(--s-bg) / 0), rgb(var(--s-bg)));
}
.app-photo .chat-composer {
  background: rgb(var(--s-bg) / .88);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
}
.app-photo .chat-composer::before { display: none; }
/* Where the card reaches the window's right side, the back-to-top button moves to the top right, under the top bar,
   so it never sits on the composer, whatever its height. */
@media (max-width: 1199px) { body:has(.chat:not(.is-empty) [data-composer]) .to-top { top: calc(var(--topbar-h) + .75rem); bottom: auto; } }

/* ---------- an answer's Markdown ---------- */

.chat-markdown { font-size: 15px; line-height: 1.7; overflow-wrap: anywhere; }
.chat-markdown > :first-child { margin-top: 0; }
.chat-markdown > :last-child { margin-bottom: 0; }
/* #208: a streaming answer's parts (chat.js paintStreaming) lay out as the answer's own blocks. */
.chat-stream-part { display: contents; }
.chat-markdown > .chat-stream-part:first-child > :first-child { margin-top: 0; }
.chat-markdown > .chat-stream-part:last-child > :last-child { margin-bottom: 0; }
.chat-markdown p, .chat-markdown ul, .chat-markdown ol, .chat-markdown blockquote,
.chat-markdown .chat-code-block, .chat-markdown .chat-table { margin: 0.75rem 0; }
.chat-markdown h1, .chat-markdown h2, .chat-markdown h3, .chat-markdown h4 { margin: 1.25rem 0 0.5rem; font-weight: 800; line-height: 1.3; }
.chat-markdown h1 { font-size: 1.4rem; }
.chat-markdown h2 { font-size: 1.2rem; }
.chat-markdown h3, .chat-markdown h4 { font-size: 1.05rem; }
.chat-markdown ul { list-style: disc; padding-left: 1.4rem; }
.chat-markdown ol { list-style: decimal; padding-left: 1.4rem; }
.chat-markdown li + li { margin-top: 0.25rem; }
.chat-markdown a { color: rgb(var(--s-brand)); text-decoration: underline; text-underline-offset: 2px; }
.chat-markdown blockquote { border-left: 3px solid rgb(var(--s-line)); padding-left: 0.9rem; color: rgb(var(--s-muted)); }
.chat-markdown hr { margin: 1.25rem 0; border: 0; border-top: 1px solid rgb(var(--s-line)); }
.chat-markdown :not(pre) > code {
  border-radius: 6px;
  background: rgb(var(--s-surface-2));
  padding: 0.1rem 0.35rem;
  font-family: "JetBrains Mono", Consolas, "Courier New", monospace;
  font-size: 0.88em;
}

.chat-table { overflow-x: auto; }
.chat-markdown table { width: 100%; border-collapse: collapse; font-size: 14px; }
.chat-markdown th, .chat-markdown td { border: 1px solid rgb(var(--s-line)); padding: 0.4rem 0.6rem; text-align: left; vertical-align: top; }
.chat-markdown th { background: rgb(var(--s-surface-2)); font-weight: 700; }
.chat-markdown tbody tr:nth-child(even) { background: rgb(var(--s-surface-2) / 0.45); }

/* ---------- code, coloured by highlight.js on the theme's tokens ---------- */

/* D199: a diagram the answer drew, its code folded under it. Mermaid draws in its light theme, so the diagram sits on
   light paper in both of the chat's themes, and a model's own colours always read. */
.chat-markdown .chat-diagram { margin: 0.75rem 0 0.25rem; overflow-x: auto; padding: 0.75rem; border: 1px solid rgb(var(--s-line)); border-radius: var(--r-md); background: #fbfaf7; text-align: center; }
.chat-diagram img { display: inline-block; max-width: 100%; height: auto; cursor: zoom-in; }
/* D199: a diagram opened large; the picture keeps its size and the stage scrolls, so any part can be reached. */
.chat-diagram-view { width: min(96vw, 90rem); height: min(92vh, 64rem); max-width: none; max-height: none; padding: 0; border: 1px solid rgb(var(--s-line)); border-radius: 14px; background: rgb(var(--s-surface)); color: rgb(var(--s-fg)); }
.chat-diagram-view[open] { display: flex; flex-direction: column; }
.chat-diagram-view::backdrop { background: rgb(0 0 0 / .6); }
.chat-diagram-view-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; padding: 0.5rem 0.75rem; border-bottom: 1px solid rgb(var(--s-line)); }
.chat-diagram-view-scale { min-width: 3.5rem; text-align: center; font-size: 13px; font-variant-numeric: tabular-nums; color: rgb(var(--s-muted)); }
.chat-diagram-view-stage { display: flex; flex: 1; min-height: 0; overflow: auto; padding: 1rem; background: #fbfaf7; cursor: grab; touch-action: pan-x pan-y; }
.chat-diagram-view-stage.is-dragging { cursor: grabbing; }
.chat-diagram-view-stage img { flex: none; margin: auto; max-width: none; user-select: none; }
/* Where the diagrams are drawn: laid out, so Mermaid can measure its words, but never seen nor reached. */
.chat-diagram-renderer { position: fixed; top: 0; left: -10000px; width: 1200px; height: 900px; border: 0; visibility: hidden; pointer-events: none; }
.chat-markdown .chat-diagram-code { margin: 0 0 0.75rem; }
.chat-diagram-code > summary { cursor: pointer; font-size: 12px; font-weight: 600; color: rgb(var(--s-muted)); }
.chat-diagram-code > .chat-code-block { margin-top: 0.4rem; }
.chat-code-block { overflow: hidden; border-radius: var(--r-md); border: 1px solid rgb(var(--s-line)); background: rgb(var(--s-surface)); }

.chat-code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  border-bottom: 1px solid rgb(var(--s-line));
  background: rgb(var(--s-surface-2));
  padding: 0.2rem 0.4rem 0.2rem 0.8rem;
  font-size: 12px;
  font-weight: 700;
  color: rgb(var(--s-muted));
}

.chat-code-block pre { margin: 0; overflow-x: auto; padding: 0.8rem 0.95rem; }
.chat-code-block code {
  font-family: "JetBrains Mono", Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre;
}

.hljs-comment, .hljs-quote { color: rgb(var(--s-muted)); font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-literal, .hljs-built_in, .hljs-doctag { color: rgb(var(--s-brand)); }
.hljs-string, .hljs-regexp, .hljs-addition, .hljs-attribute, .hljs-template-tag { color: rgb(var(--s-ok)); }
.hljs-number, .hljs-symbol, .hljs-bullet, .hljs-variable, .hljs-template-variable, .hljs-link { color: rgb(var(--s-warn)); }
.hljs-title, .hljs-section, .hljs-type, .hljs-class .hljs-title, .hljs-name, .hljs-selector-id, .hljs-selector-class { color: rgb(var(--s-accent)); font-weight: 700; }
.hljs-meta, .hljs-params, .hljs-attr, .hljs-property { color: rgb(var(--s-fg)); }
.hljs-deletion { color: rgb(var(--s-err)); }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 700; }

/* ---------- a question and its answer printed for Save as PDF (D127) ---------- */

.chat-print { display: none; }

/* ---------- the background photo (#119, the template's chat-photo.html) ----------
   The layers, the veil's three steps and the glass are the theme's (.photo-bg, .photo-veil, [data-veil], .app-photo).
   Here only what the chat adds: its answers sit on a reading surface, the composer lets the picture through, the
   strength dropdown fits the top bar, and the credit moves under the top bar where the composer would cover it. */
.photo-strength { width: auto; padding-block: 0.3rem; font-size: 13px; }
/* The credit belongs to the top bar, whose height never changes. The theme's own rule places the template's floating
   pill, which SophIA does not use: a page still carrying one outside the bar (a host running an older build) hides it,
   so nothing floats over the chat and nothing takes a row of its own at the foot of the page. */
body > .photo-credit { display: none; }
.topbar .photo-credit { position: static; display: inline-flex; max-width: 18rem; padding-inline: 0.5rem; color: rgb(var(--s-muted)); text-decoration: none; }
.topbar .photo-credit:hover { color: rgb(var(--s-fg)); }
@media (max-width: 1023px) { .topbar .photo-credit { max-width: 8rem; } }
.photo-credit .dot { flex: none; color: rgb(var(--s-accent)); }
.photo-credit [data-photo-credit-text] { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (prefers-reduced-transparency: reduce) { .photo-strength, .photo-credit { display: none; } }
.app-photo .chat-assistant {
  padding: 0.9rem 1rem;
  border-radius: var(--r-lg);
  background: rgb(var(--s-surface) / .82);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
}
.dark .app-photo .chat-assistant { background: rgb(var(--s-surface) / .72); }

@media print {
  .photo-bg, .photo-veil, .photo-credit, .photo-strength { display: none !important; }
  body.is-printing > *:not(.chat-print) { display: none !important; }
  body.is-printing { background: #fff; color: #111; }
  body.is-printing .chat-print { display: block; max-width: 46rem; margin: 0 auto; font-size: 11pt; }
  .chat-print-head { display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; align-items: baseline; padding-bottom: 0.5rem; margin-bottom: 1rem; border-bottom: 1px solid #ccc; color: #555; font-size: 9pt; }
  .chat-print-brand { font-weight: 800; color: #9f4934; font-size: 11pt; }
  .chat-print-label { margin: 0; font-size: 8pt; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: #777; }
  body.is-printing .chat-print-exchange { break-inside: auto; }
  body.is-printing .chat-print-exchange + .chat-print-exchange { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid #ddd; }
  .chat-print-question { margin: 0.25rem 0 1rem; padding: 0.6rem 0.8rem; border-left: 3px solid #9f4934; background: #f6f3f1; white-space: pre-wrap; }
  /* #116, D140: the citations, the product cards, the pictures and the sources print with the answer. */
  body.is-printing .chat-cite { border-color: #ccc; background: #f6f3f1; color: #555; }
  body.is-printing .chat-product { border-color: #ccc; background: #fff; break-inside: avoid; }
  body.is-printing .chat-sources { color: #555; }
  body.is-printing .chat-sources summary { list-style: none; }
  body.is-printing .chat-sources a { color: #111; }
  /* #131: a live result's text prints whole; on screen it scrolls past its height, on paper it would run over what follows. */
  body.is-printing .chat-live-title { color: #111; }
  body.is-printing .chat-live-text { max-height: none; overflow: visible; border-color: #ccc; background: #fff; color: #111; }
  body.is-printing .chat-sources a.chat-live-open { border-color: #ccc; color: #555; }
  .chat-print .chat-code-head button { display: none; }
  .chat-print pre, .chat-print .chat-table { overflow: visible; white-space: pre-wrap; }
  /* #208: a code block's long lines wrap on paper, a long word or address too; on screen the block scrolls sideways. */
  .chat-print .chat-code-block { overflow: visible; }
  .chat-print .chat-code-block code { white-space: pre-wrap; overflow-wrap: anywhere; }
  .chat-print table, .chat-print pre, .chat-print blockquote, .chat-print li { break-inside: avoid; }
  .chat-print .chat-markdown th, .chat-print .chat-markdown td { border-color: #bbb; }
  .chat-print .chat-markdown a { color: #111; }
}

/* ---------- the composer grows with its text, then scrolls; no handle to drag (as in Claude and ChatGPT) ---------- */

.chat-composer textarea,
.chat-editor textarea {
  resize: none;
  min-height: 3.25rem;
  max-height: 14rem;
  overflow-y: auto;
}

/* ---------- feedback (#118, D104, D160) ----------
   Two quiet icons among the answer's actions; the chosen one stays filled. The reasons panel sits in the flow under the
   answer, and the one question about a previous conversation is a small card at the top of a new chat. Nothing floats
   over the conversation. */
.chat-rate[aria-pressed="true"] { color: rgb(var(--s-brand)); }
.chat-rate[aria-pressed="true"] svg { fill: currentColor; fill-opacity: .18; }
.chat-feedback-note { font-size: .75rem; color: rgb(var(--s-muted)); margin-inline-start: .35rem; }
.chat-feedback { display: grid; gap: .6rem; margin-top: .5rem; padding: .85rem 1rem; border: 1px solid rgb(var(--s-line)); border-radius: .75rem; background: rgb(var(--s-surface-2)); }
.chat-feedback-title { margin: 0; font-size: .875rem; font-weight: 600; }
.chat-feedback-chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chat-chip { padding: .3rem .7rem; border: 1px solid rgb(var(--s-line)); border-radius: 999px; background: transparent; color: rgb(var(--s-fg)); font-size: .8125rem; cursor: pointer; }
.chat-chip:hover { background: rgb(var(--s-surface)); }
.chat-chip[aria-pressed="true"] { border-color: rgb(var(--s-brand)); background: rgb(var(--s-brand) / .12); color: rgb(var(--s-brand)); }
.chat-chip:focus-visible, .chat-star:focus-visible { outline: 2px solid rgb(var(--s-brand)); outline-offset: 1px; }
.chat-feedback-comment { width: 100%; min-height: 2.25rem; resize: vertical; padding: .45rem .6rem; border: 1px solid rgb(var(--s-line)); border-radius: .5rem; background: rgb(var(--s-surface)); color: rgb(var(--s-fg)); font: inherit; font-size: .875rem; }
.chat-feedback-actions { display: flex; justify-content: flex-end; gap: .5rem; }
.chat-question { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .9rem; margin: 0 auto 1rem; max-width: 40rem; padding: .7rem .9rem; border: 1px solid rgb(var(--s-line)); border-radius: .75rem; background: rgb(var(--s-surface-2)); }
.chat-question-text { margin: 0; flex: 1 1 16rem; font-size: .875rem; }
.chat-question-stars { display: inline-flex; gap: .15rem; }
.chat-star { padding: 0 .1rem; border: 0; background: transparent; color: rgb(var(--s-muted)); font-size: 1.25rem; line-height: 1; cursor: pointer; }
.chat-star.is-lit { color: rgb(var(--s-warn)); }
.chat-question-close { margin-inline-start: auto; }

/* #117 (D223, D224): the weather in the top bar — an icon, the temperature and the place, the conditions as its title. */
.chat-weather { display: inline-flex; align-items: center; gap: .3rem; padding-inline: .35rem; font-size: 13px; font-weight: 600; color: rgb(var(--s-muted)); white-space: nowrap; }
.chat-weather-icon { display: inline-flex; color: rgb(var(--s-accent)); }
.chat-weather-temp { color: rgb(var(--s-fg)); }
.chat-weather-place { max-width: 10rem; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 639px) { .chat-weather-place { display: none; } }

/* #117 (D222): a tool that changes something asks first — what it will do, its details, Yes and No. */
.tool-confirm { margin-top: .6rem; padding: .75rem .9rem; border: 1px solid rgb(var(--s-accent) / .45); border-radius: .75rem; background: rgb(var(--s-accent) / .08); }
.tool-confirm-title { font-size: 14px; font-weight: 700; }
.tool-confirm-details { display: grid; grid-template-columns: auto 1fr; gap: .2rem .75rem; margin: .5rem 0 .65rem; font-size: 13px; }
.tool-confirm-details dt { font-weight: 600; color: rgb(var(--s-muted)); }
.tool-confirm-details dd { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.tool-confirm-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.tool-confirm-note { margin-top: .4rem; font-size: 12px; color: rgb(var(--s-muted)); }

/* ---------- a conversation's files (#132, D261) ---------- */

/* The files staged in the composer: chips above the question, each with its kind, name, size and a remove. */
[data-composer-box] { position: relative; }
.chat-attachments { display: flex; flex-wrap: wrap; gap: .4rem; margin: 0 0 .35rem; padding: .25rem .25rem 0; list-style: none; }
.chat-file-chip, .chat-file-card, .chat-file-row { position: relative; display: flex; align-items: center; gap: .55rem; min-width: 0; border: 1px solid rgb(var(--s-line)); border-radius: .7rem; background: rgb(var(--s-surface)); }
.chat-file-chip { max-width: 15rem; padding: .35rem 1.9rem .35rem .4rem; overflow: hidden; }
.chat-file-kind { flex: none; display: grid; place-items: center; width: 2.1rem; height: 2.1rem; overflow: hidden; border-radius: .45rem; background: rgb(var(--s-brand) / .1); color: rgb(var(--s-brand)); font-size: 10px; font-weight: 800; letter-spacing: .02em; }
.chat-file-kind img { width: 100%; height: 100%; object-fit: cover; }
.chat-file-text { display: grid; min-width: 0; line-height: 1.3; }
.chat-file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 600; color: rgb(var(--s-fg)); text-decoration: none; }
a.chat-file-name[href]:hover { color: rgb(var(--s-brand)); text-decoration: underline; text-underline-offset: 2px; }
.chat-file-meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11.5px; color: rgb(var(--s-muted)); }
.chat-file-unstage { position: absolute; top: .3rem; right: .3rem; display: grid; place-items: center; width: 1.35rem; height: 1.35rem; border-radius: 999px; color: rgb(var(--s-muted)); }
.chat-file-unstage svg { width: .85rem; height: .85rem; }
.chat-file-unstage:hover { background: rgb(var(--s-surface-2)); color: rgb(var(--s-fg)); }
.chat-file-unstage:disabled { opacity: .4; cursor: default; }
.chat-file-progress { position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: transparent; }
.chat-file-progress > span { display: block; height: 100%; width: 0; background: rgb(var(--s-brand)); transition: width .2s var(--ease); }
.chat-file-chip:not(.is-uploading) .chat-file-progress { display: none; }
.chat-file-chip.is-failed, .chat-file-card.is-failed, .chat-file-row.is-failed { border-color: rgb(var(--s-err) / .5); }
.chat-file-chip.is-failed .chat-file-meta, .chat-file-card.is-failed .chat-file-meta, .chat-file-row.is-failed .chat-file-meta { color: rgb(var(--s-err)); }

/* A file dropped on the composer: the box says it will take it. */
.chat-drop { position: absolute; inset: 0; z-index: 2; display: grid; place-items: center; border: 2px dashed rgb(var(--s-brand) / .6); border-radius: inherit; background: rgb(var(--s-surface) / .92); color: rgb(var(--s-brand)); font-size: 14px; font-weight: 700; pointer-events: none; }

/* The files of a sent question, as cards over its bubble; a removed file's card stays, greyed, without its download. */
.chat-file-cards { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .4rem; max-width: 85%; margin: 0; padding: 0; list-style: none; }
.chat-file-card { max-width: 16rem; padding: .4rem .7rem .4rem .4rem; }
.chat-file-card.is-picture .chat-file-kind { width: 2.6rem; height: 2.6rem; }
.chat-file-card.is-removed { opacity: .55; border-style: dashed; }
.chat-file-card.is-removed .chat-file-kind { background: rgb(var(--s-surface-2)); color: rgb(var(--s-muted)); }
.chat-user.is-pending .chat-file-cards { opacity: .65; }
.chat-file-cards.is-made { justify-content: flex-start; max-width: 100%; margin-top: .6rem; }
.chat-file-cards.is-made .chat-file-card { max-width: 20rem; }
.chat-file-origin { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11.5px; color: rgb(var(--s-brand)); }
.chat-file-origin a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.chat-file-open { flex: none; margin-left: .2rem; padding: .2rem .5rem; border-radius: .45rem; font-size: 12px; font-weight: 600; color: rgb(var(--s-brand)); text-decoration: none; }
.chat-file-open:hover { background: rgb(var(--s-brand) / .1); }

/* The badge on a conversation's row: how many files it holds; it opens their panel. */
.session-files { position: absolute; right: 2.2rem; top: 50%; transform: translateY(-50%); display: inline-flex; align-items: center; gap: .15rem; height: 1.3rem; padding: 0 .4rem; border-radius: 999px; background: rgb(var(--s-brand) / .1); color: rgb(var(--s-brand)); font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums; }
.session-files svg { width: .8rem; height: .8rem; }
.session-files:hover { background: rgb(var(--s-brand) / .2); }
.session-files:focus-visible { outline: 2px solid rgb(var(--s-brand)); outline-offset: 1px; }
.sidebar.is-collapsed .session-files { display: none; }
.session-row.has-files .nav-link { padding-right: 5rem; }

/* The files panel: a sheet on the right, each file with its download and a remove. */
.chat-files-panel { position: fixed; inset: 0 0 0 auto; z-index: 70; width: min(100vw, 26rem); max-width: none; height: 100dvh; max-height: none; margin: 0; padding: 0; border: 0; border-left: 1px solid rgb(var(--s-line)); background: rgb(var(--s-surface)); color: rgb(var(--s-fg)); box-shadow: -12px 0 32px rgb(0 0 0 / .12); }
.chat-files-panel[open] { display: flex; flex-direction: column; }
.chat-files-head { display: flex; align-items: center; gap: .5rem; min-height: var(--topbar-h); padding: .5rem .75rem .5rem 1rem; border-bottom: 1px solid rgb(var(--s-line)); }
.chat-files-title { font-weight: 700; font-size: 15px; }
.chat-files-count { flex: 1; font-size: 12px; font-weight: 600; color: rgb(var(--s-muted)); }
.chat-files-conversation { margin: .75rem 1rem 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; color: rgb(var(--s-muted)); }
.chat-files-conversation:empty { display: none; }
.chat-files-list { display: grid; gap: .45rem; margin: 0; padding: .75rem 1rem; overflow-y: auto; list-style: none; }
.chat-file-row { padding: .45rem .35rem .45rem .45rem; }
.chat-file-row .chat-file-text { flex: 1; }
.chat-icon-btn.is-danger:hover { color: rgb(var(--s-err)); background: rgb(var(--s-err) / .08); }
.chat-icon-btn:disabled { opacity: .4; cursor: default; }
.chat-files-empty { margin: 1rem; font-size: 13.5px; color: rgb(var(--s-muted)); }
.chat-files-note { margin: auto 1rem 1rem; padding-top: .75rem; border-top: 1px solid rgb(var(--s-line)); font-size: 12px; color: rgb(var(--s-muted)); }
@media print { .chat-file-cards, .chat-attachments { display: none !important; } }