@layer components {
  /* An artifact in its isolated frame, under the caption that says who generated it. */
  .artifact-frame { display: flex; flex-direction: column; gap: 8px; margin: 0; min-width: 0; }
  .artifact-frame-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
  .artifact-caption { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
  .artifact-label { color: var(--muted-foreground); font-size: 13px; line-height: 1.45; }
  /* What the artifact's script reads, it may send out: nothing sensitive is typed there. */
  .artifact-warning { color: var(--foreground); font-size: 13px; font-weight: 500; line-height: 1.45; }
  /* The artifact paints its own page: light, as an agent writes it, whatever the app's theme. */
  .artifact-iframe {
    display: block; width: 100%; height: 600px; border: 1px solid var(--border); border-radius: var(--radius-lg);
    background: white; color-scheme: light;
  }
  .document-view--page .artifact-iframe, .document-history .artifact-iframe { height: max(600px, calc(100dvh - 260px)); }
  /* In the side panel the artifact fills what the header leaves: the panel, its pane and the frames down to the iframe
     are one column and the iframe takes the rest. 360px at least: a short window scrolls the panel instead. */
  @media (min-width: 1100px) {
    .app-panel:has(.document-view--panel > .artifact-frame) { display: flex; flex-direction: column; }
    .app-panel:has(.document-view--panel > .artifact-frame) turbo-frame[data-panel-pane="documents"] { flex: 1; }
    .document-tasks:has(> .document-view--panel > .artifact-frame) { flex: 1; display: flex; flex-direction: column; }
    .document-tasks > .document-view--panel:has(> .artifact-frame:not(.is-fullscreen)) { flex: 1; }
    .document-view--panel > .artifact-frame:not(.is-fullscreen) { flex: 1; }
    .document-view--panel > .artifact-frame:not(.is-fullscreen) .artifact-iframe { flex: 1; height: auto; min-height: 360px; }
  }
  .artifact-support-note {
    display: grid; place-items: center; min-height: 160px; margin: 0; padding: 16px;
    border: 1px dashed var(--border); border-radius: var(--radius-lg); color: var(--muted-foreground); font-size: 13px;
  }

  /* Full screen, on request: the frame stays where it is, only the figure's box grows. Close and download exist only
     then; the request for a change that leaves for the thread is the phone's. */
  .artifact-fullscreen-close, .artifact-fullscreen-download { display: none; }
  .artifact-request[data-artifact-request-thread-param] { display: none; }

  .artifact-frame.is-fullscreen {
    position: fixed; inset: 0; z-index: 30; gap: 0; background: var(--background);
    padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
  }
  .artifact-frame.is-fullscreen :is(.artifact-caption, .artifact-request, .artifact-fullscreen) { display: none; }
  .artifact-frame.is-fullscreen .artifact-frame-head { flex-wrap: nowrap; justify-content: flex-end; padding: 4px 8px; }
  .artifact-frame.is-fullscreen :is(.artifact-fullscreen-close, .artifact-fullscreen-download) { display: inline-flex; }
  .artifact-frame.is-fullscreen .artifact-iframe { flex: 1; height: auto; min-height: 0; border: 0; border-radius: 0; }
  :root:has(.artifact-frame.is-fullscreen) { overflow: hidden; }
  body:has(.artifact-frame.is-fullscreen) :is(.document-bar, .document-topbar) { display: none; }

  /* A PDF read as page pictures: the caption stays (it names the document) and the pages scroll under it. */
  .pdf-reader.is-fullscreen .artifact-caption { display: flex; flex: 1; }
  .pdf-reader.is-fullscreen .artifact-frame-head { justify-content: space-between; align-items: center; }
  .pdf-reader .artifact-label { color: var(--foreground); font-weight: 600; overflow-wrap: anywhere; }
  .pdf-reader-scroll {
    flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 8px 16px 24px;
    display: flex; flex-direction: column; align-items: center; gap: 12px; background: var(--muted);
  }
  .pdf-reader-more { display: block; width: min(100%, 900px); text-align: center; }
  .pdf-reader-page { margin: 0; width: min(100%, 900px); }
  /* A page keeps a white sheet in the dark theme, as paper does; the box is sized before the picture arrives. */
  .pdf-reader-page img {
    display: block; width: 100%; height: auto; background: white; border: 1px solid var(--border);
    border-radius: var(--radius-sm, 4px);
  }

  @media (max-width: 1099px) {
    .pdf-reader-scroll { padding: 4px 4px calc(16px + var(--safe-bottom)); }
    .artifact-request[data-artifact-request-thread-param] { display: inline-flex; }
    .artifact-frame-head .button { height: var(--tap); }
    .document-view--page .artifact-iframe { height: max(360px, calc(100dvh - 330px - var(--safe-bottom))); }
  }
}
