/* Result reading: rich text, JSON, tables, code, attachment cards and the
   file viewer. Shared by the studio (index.html) and the customer product
   page (products.html). Colors come from each page's tokens with fallbacks.
   Declared on body: the studio sets its theme tokens on body, so var() must
   resolve there rather than on :root. */
body {
  --rc-ink: var(--ink, #1f2b26);
  --rc-soft: var(--ink-soft, #5d6a63);
  --rc-line: var(--line, #e1e6de);
  --rc-paper: var(--paper, #ffffff);
  --rc-sunk: var(--soft, #f1f4ee);
  --rc-accent: var(--accent, #0b6e5c);
  --rc-radius: 10px;
  --rc-mono: ui-monospace, "Cascadia Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

/* ---------- Rich text ---------- */
.rich-text { white-space: normal; font-size: 14px; line-height: 1.8; color: var(--rc-ink); overflow-wrap: anywhere; min-width: 0; }
.rich-text > :first-child { margin-top: 0; }
.rich-text > :last-child { margin-bottom: 0; }
.rich-text p { margin: 0 0 .75em; }
.rich-text :is(h2, h3, h4, h5, h6) { margin: 1.2em 0 .5em; line-height: 1.45; font-weight: 600; color: var(--rc-ink); }
.rich-text h2 { font-size: 18px; }
.rich-text h3 { font-size: 16px; }
.rich-text :is(h4, h5, h6) { font-size: 14px; }
.rich-text :is(ul, ol) { margin: 0 0 .8em; padding-left: 1.5em; }
.rich-text li { margin: .2em 0; }
.rich-text li > :is(ul, ol) { margin: .2em 0; }
.rich-text .rt-task { list-style: none; margin-left: -1.3em; display: flex; gap: .5em; align-items: baseline; }
.rich-text .rt-check { flex: none; width: .95em; height: .95em; border: 1.5px solid var(--rc-soft); border-radius: 3px; transform: translateY(.12em); }
.rich-text .rt-check.is-done { background: var(--rc-accent); border-color: var(--rc-accent); box-shadow: inset 0 0 0 2px var(--rc-paper); }
.rich-text blockquote { margin: 0 0 .8em; padding: .2em 0 .2em 1em; border-left: 3px solid var(--rc-line); color: var(--rc-soft); }
.rich-text hr { border: 0; border-top: 1px solid var(--rc-line); margin: 1.2em 0; }
.rich-text a { color: var(--rc-accent); text-decoration: underline; text-underline-offset: 2px; }
.rich-text code, .rt-plain code { font-family: var(--rc-mono); font-size: .9em; padding: .1em .35em; border-radius: 4px; background: var(--rc-sunk); }
.rich-text del { color: var(--rc-soft); }
.rt-plain { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.8; }
.rt-plain a { color: var(--rc-accent); }
.rt-truncated { color: var(--rc-soft); font-size: 12px; }

/* Code */
.rt-code { margin: 0 0 .9em; border: 1px solid var(--rc-line); border-radius: var(--rc-radius); background: var(--rc-sunk); overflow: hidden; min-width: 0; }
.rt-code figcaption { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 6px 4px 12px; border-bottom: 1px solid var(--rc-line); font-size: 11px; color: var(--rc-soft); letter-spacing: .02em; }
.rt-code pre { margin: 0; padding: 12px 14px; overflow: auto; max-height: 480px; font: 12.5px/1.65 var(--rc-mono); white-space: pre; tab-size: 2; }
.rt-code pre code { padding: 0; background: none; font-size: inherit; }
.rt-copy { border: 0; background: transparent; color: var(--rc-soft); font: inherit; font-size: 12px; padding: 4px 8px; border-radius: 6px; cursor: pointer; }
.rt-copy:hover { color: var(--rc-ink); background: var(--rc-paper); }

/* Tables scroll inside their own frame and never widen the page. */
.rt-table-scroll { max-width: 100%; overflow: auto; margin: 0 0 .9em; border: 1px solid var(--rc-line); border-radius: var(--rc-radius); background: var(--rc-paper); max-height: 520px; }
.rt-table { border-collapse: collapse; width: max-content; min-width: 100%; font-size: 13px; line-height: 1.55; }
.rt-table :is(th, td) { padding: 7px 12px; border-bottom: 1px solid var(--rc-line); text-align: left; vertical-align: top; max-width: 420px; overflow-wrap: anywhere; }
.rt-table th { position: sticky; top: 0; z-index: 1; background: var(--rc-sunk); font-weight: 600; color: var(--rc-ink); white-space: nowrap; }
.rt-table tbody tr:last-child td { border-bottom: 0; }
.rt-table tbody tr:hover td { background: color-mix(in srgb, var(--rc-accent) 5%, transparent); }

/* JSON */
.rt-json { margin: 0 0 .9em; border: 1px solid var(--rc-line); border-radius: var(--rc-radius); background: var(--rc-paper); min-width: 0; }
.rt-json-toolbar { display: flex; align-items: center; gap: 2px; padding: 4px 6px 4px 12px; border-bottom: 1px solid var(--rc-line); font-size: 11px; color: var(--rc-soft); }
.rt-json-toolbar > span { margin-right: auto; letter-spacing: .06em; }
.rt-json-toolbar button { border: 0; background: transparent; color: var(--rc-soft); font: inherit; font-size: 12px; padding: 4px 9px; border-radius: 6px; cursor: pointer; }
.rt-json-toolbar button[aria-pressed="true"] { color: var(--rc-ink); background: var(--rc-sunk); font-weight: 600; }
.rt-json-tree, .rt-json-tree ul { list-style: none; margin: 0; padding: 0 0 0 1.1em; font: 12.5px/1.75 var(--rc-mono); }
.rt-json-tree { padding: 10px 12px; max-height: 520px; overflow: auto; }
.rt-json-tree summary { cursor: pointer; border-radius: 4px; }
.rt-json-tree summary:hover { background: var(--rc-sunk); }
.rt-json-key { color: var(--rc-ink); font-weight: 600; }
.rt-json-colon { color: var(--rc-soft); }
.rt-json-summary, .rt-json-empty, .rt-json-null { color: var(--rc-soft); }
.rt-json-string { color: #2f6b3f; overflow-wrap: anywhere; }
.rt-json-number, .rt-json-boolean { color: #8a4a12; }
[data-theme="dark"] .rt-json-string { color: #9fd8a9; }
[data-theme="dark"] .rt-json-number, [data-theme="dark"] .rt-json-boolean { color: #f0bd85; }
@media (prefers-color-scheme: dark) {
  body:not([data-theme]) .rt-json-string { color: #9fd8a9; }
  body:not([data-theme]) :is(.rt-json-number, .rt-json-boolean) { color: #f0bd85; }
  body:not([data-theme]) :is(.attachment-warning, .attachment-archive-summary li small) { color: #f0b48a; }
}
.rt-json-more { color: var(--rc-soft); font-style: italic; }
.rt-json-raw { margin: 0; padding: 12px 14px; max-height: 520px; overflow: auto; font: 12.5px/1.65 var(--rc-mono); white-space: pre; }
.rt-json-raw-note { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin: 0; padding: 6px 14px 8px; border-top: 1px solid var(--rc-line); font-size: 12px; color: var(--rc-soft); }

/* ---------- Attachment cards (in conversations and trial) ---------- */
/* Row direction overrides lifecycle.css's column stack so the 260px basis below is a width, not a height. */
.message-attachments { display: flex; flex-direction: row; flex-wrap: wrap; align-items: flex-start; gap: 10px; margin-top: 10px; min-width: 0; }
.message-attachment { margin: 0; flex: 1 1 260px; max-width: 100%; min-width: 0; display: flex; flex-direction: column; gap: 8px; padding: 10px; border: 1px solid var(--rc-line); border-radius: 12px; background: var(--rc-paper); }
.message-attachment.image, .message-attachment.video { flex-basis: 280px; max-width: 520px; }
.message-attachment:has(.sheet-view) { flex-basis: 100%; max-width: 100%; }
.message-attachment figcaption { display: flex; align-items: center; justify-content: space-between; gap: 6px 10px; flex-wrap: wrap; font-size: 12px; color: var(--rc-soft); min-width: 0; }
.attachment-caption { display: flex; align-items: baseline; gap: 6px; min-width: 0; overflow-wrap: anywhere; color: var(--rc-ink); }
.attachment-caption small { color: var(--rc-soft); }
.attachment-actions { display: inline-flex; gap: 2px; flex-wrap: wrap; margin-left: auto; }
.attachment-actions :is(a, button) { font-size: 12px; padding: 3px 8px; border-radius: 6px; }
.message-attachment .attachment-file { display: flex; align-items: center; gap: 10px; min-width: 0; color: var(--rc-ink); text-decoration: none; }
.attachment-file-icon { flex: none; display: grid; place-items: center; width: 36px; height: 36px; border-radius: 9px; background: var(--rc-sunk); color: var(--rc-accent); }
.attachment-file-icon svg { width: 20px; height: 20px; }
.attachment-file-name { display: flex; flex-direction: column; min-width: 0; }
.attachment-file-name strong { font-size: 13px; font-weight: 600; overflow-wrap: anywhere; }
.attachment-file-name small { font-size: 11px; color: var(--rc-soft); }
.attachment-image { display: block; padding: 0; border: 0; background: var(--rc-sunk); border-radius: 8px; overflow: hidden; cursor: zoom-in; }
.attachment-image img { display: block; width: 100%; max-height: 360px; object-fit: contain; }
.message-attachment video { width: 100%; max-height: 360px; border-radius: 8px; background: #000; }
.message-attachment audio { width: 100%; min-width: 0; }
.generated-media-label { display: inline-block; padding: 1px 6px; border-radius: 999px; font-size: 10px; background: color-mix(in srgb, var(--rc-accent) 12%, transparent); color: var(--rc-accent); }
.audio-transcript { margin: 0; font-size: 12px; line-height: 1.7; color: var(--rc-ink); white-space: pre-wrap; }
.audio-transcript span { display: block; font-size: 11px; color: var(--rc-soft); }
.attachment-reading { display: flex; flex-direction: column; gap: 6px; min-width: 0; font-size: 12px; color: var(--rc-soft); white-space: normal; }
.attachment-reading > p { margin: 0; line-height: 1.6; }
.attachment-excerpt { margin: 0; padding: 8px 10px; border-left: 3px solid var(--rc-line); background: var(--rc-sunk); border-radius: 0 8px 8px 0; color: var(--rc-ink); line-height: 1.7; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 9.5em; overflow: hidden; }
.attachment-warning { margin: 0; color: #9a4b1f; font-size: 12px; line-height: 1.6; }
[data-theme="dark"] .attachment-warning { color: #f0b48a; }
.attachment-archive-summary summary { cursor: pointer; color: var(--rc-ink); }
.attachment-archive-summary ul { margin: 6px 0 0; padding-left: 1.2em; }
.attachment-archive-summary li small { margin-left: 6px; color: #9a4b1f; }

/* Sheets */
.sheet-view { min-width: 0; }
.sheet-title { margin: 0 0 6px; font-size: 12px; font-weight: 600; color: var(--rc-ink); }
.sheet-tabs { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: thin; }
.sheet-tabs button { flex: none; display: inline-flex; align-items: baseline; gap: 6px; border: 1px solid var(--rc-line); background: var(--rc-paper); color: var(--rc-soft); padding: 4px 10px; border-radius: 999px; font: inherit; font-size: 12px; cursor: pointer; }
.sheet-tabs button small { font-size: 10px; }
.sheet-tabs button[aria-selected="true"] { color: var(--rc-paper); background: var(--rc-accent); border-color: var(--rc-accent); }
.sheet-note { margin: -4px 0 0; font-size: 11px; color: var(--rc-soft); line-height: 1.6; }
.attachment-reading .rt-table-scroll { max-height: 260px; margin-bottom: 8px; }

/* On-demand file previews (file-preview-view.js) */
.fp-view { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.fp-view .rt-table-scroll { max-height: min(62vh, 640px); }
.fp-view .sheet-table th.fp-row, .fp-view .sheet-table th.fp-corner { position: sticky; left: 0; z-index: 1; background: var(--rc-sunk); color: var(--rc-soft); font-weight: 400; text-align: right; }
.fp-view .sheet-table thead th { position: sticky; top: 0; background: var(--rc-sunk); }
.fp-view .sheet-table thead th.fp-corner { z-index: 2; }
.fp-path { overflow-wrap: anywhere; min-width: 16ch; }
.fp-flag { display: inline-block; margin-right: 4px; padding: 0 6px; border-radius: 999px; font-size: 11px; background: var(--rc-sunk); color: var(--rc-soft); }
.fp-flag.is-warning { background: #f6e7d8; color: #8a4a12; }
.fp-raw > summary { cursor: pointer; font-size: 12px; color: var(--rc-soft); margin-bottom: 8px; }
.fp-status { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }

/* ---------- File viewer ---------- */
.file-viewer { width: min(1180px, calc(100vw - 32px)); height: min(860px, calc(100dvh - 32px)); max-width: none; max-height: none; padding: 0; border: 1px solid var(--rc-line); border-radius: 16px; background: var(--rc-paper); color: var(--rc-ink); box-shadow: 0 24px 80px #0f1f1a33; overflow: hidden; }
.file-viewer[open] { display: flex; flex-direction: column; }
.file-viewer::backdrop { background: #0d1a1566; }
.file-viewer-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px 14px 22px; border-bottom: 1px solid var(--rc-line); }
.file-viewer-head > div:first-child { min-width: 0; flex: 1; }
.file-viewer-head h2 { margin: 2px 0 0; font-size: 16px; font-weight: 600; overflow-wrap: anywhere; }
.file-viewer-kind { margin: 0; font-size: 11px; color: var(--rc-soft); }
.file-viewer-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.file-viewer .dialog-close { flex: none; width: 36px; height: 36px; border: 0; border-radius: 8px; background: transparent; color: var(--rc-soft); font-size: 22px; cursor: pointer; }
.file-viewer .dialog-close:hover { background: var(--rc-sunk); color: var(--rc-ink); }
.file-viewer-body { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr); }
.file-viewer.has-nav .file-viewer-body { grid-template-columns: 240px minmax(0, 1fr); }
.file-viewer-nav { border-right: 1px solid var(--rc-line); overflow: auto; padding: 12px 8px; background: var(--rc-sunk); }
.file-viewer-nav-title { margin: 10px 8px 6px; font-size: 11px; color: var(--rc-soft); }
.file-viewer-nav button { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; width: 100%; text-align: left; border: 0; background: transparent; color: var(--rc-ink); padding: 8px 10px; border-radius: 8px; font: inherit; font-size: 13px; cursor: pointer; overflow-wrap: anywhere; }
.file-viewer-nav button small { font-size: 11px; color: var(--rc-soft); }
.file-viewer-nav button:hover { background: var(--rc-paper); }
.file-viewer-nav button[aria-current="true"] { background: var(--rc-paper); box-shadow: inset 3px 0 0 var(--rc-accent); font-weight: 600; }
.file-viewer-main { overflow: auto; padding: 20px 24px 28px; min-width: 0; outline: none; }
.viewer-entry > header { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.viewer-entry > header h3 { margin: 0; font-size: 15px; overflow-wrap: anywhere; }
.viewer-entry-status { font-size: 11px; padding: 1px 8px; border-radius: 999px; background: #f6e7d8; color: #8a4a12; }
.viewer-entry-status.is-ready { background: color-mix(in srgb, var(--rc-accent) 12%, transparent); color: var(--rc-accent); }
.viewer-entry + .viewer-entry { margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--rc-line); }
.viewer-section { margin-bottom: 20px; min-width: 0; }
.viewer-section > h4 { margin: 0 0 8px; font-size: 12px; font-weight: 600; color: var(--rc-soft); letter-spacing: .04em; }
.viewer-text { padding: 14px 16px; border: 1px solid var(--rc-line); border-radius: var(--rc-radius); background: var(--rc-paper); font-size: 14px; max-width: 78ch; }
.viewer-text + .button { margin-top: 10px; }
.viewer-assets { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.viewer-assets figure { margin: 0; display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--rc-soft); }
.viewer-assets img { width: 100%; aspect-ratio: 4 / 3; object-fit: contain; background: var(--rc-sunk); border-radius: 8px; }
.viewer-asset-file { padding: 12px; border: 1px solid var(--rc-line); border-radius: 10px; color: var(--rc-ink); }
.viewer-asset-file svg { width: 22px; height: 22px; color: var(--rc-accent); }
.viewer-image { display: grid; place-items: center; min-height: 100%; background: var(--rc-sunk); border-radius: 10px; overflow: auto; }
.viewer-image img { max-width: 100%; max-height: calc(100dvh - 200px); object-fit: contain; cursor: zoom-in; }
.viewer-image img.is-actual-size { max-width: none; max-height: none; cursor: zoom-out; }
.viewer-media { width: 100%; max-height: calc(100dvh - 220px); border-radius: 10px; }
video.viewer-media { background: #000; }
.viewer-pdf { min-height: 200px; }
.viewer-pdf iframe { width: 100%; height: calc(100dvh - 230px); min-height: 420px; border: 1px solid var(--rc-line); border-radius: 10px; background: #fff; }
.viewer-loading, .viewer-empty, .viewer-hint { color: var(--rc-soft); font-size: 13px; }

@media (max-width: 760px) {
  .file-viewer { width: 100vw; height: 100dvh; border-radius: 0; border: 0; }
  .file-viewer.has-nav .file-viewer-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .file-viewer-nav { display: flex; gap: 4px; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--rc-line); padding: 8px; }
  .file-viewer-nav-title { display: none; }
  .file-viewer-nav button { flex: none; width: auto; max-width: 220px; }
  .file-viewer-head { flex-wrap: wrap; padding: 12px 12px 12px 16px; }
  .file-viewer-actions { order: 3; width: 100%; }
  .file-viewer-main { padding: 16px; }
  .message-attachment.image, .message-attachment.video { max-width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  .file-viewer, .file-viewer::backdrop { animation: none !important; transition: none !important; }
}
