/* media.css: inline media previews (gallery, video and audio players, PDF
   cards) and the full-screen media viewer (media.js). Published pages inline
   this file too, so it only uses tokens they also define, with fallbacks. */

.download-widget-previews,
.media-link-previews { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
.download-widget-previews { margin: 0 0 10px; }

/* Buttons that hold a preview: no button look. */
.media-preview { font: inherit; color: inherit; }
button.media-preview { padding: 0; border: 0; background: none; cursor: zoom-in; text-align: left; }
button.media-preview:focus-visible,
.media-inline-image:focus-visible { outline: 2px solid var(--accent, #c92a2a); outline-offset: 2px; }

/* One image: shown large. */
.media-image { display: block; max-width: 100%; }
.media-image img { display: block; max-width: 100%; max-height: 360px; border-radius: var(--radius-sm, 6px);
  border: 1px solid var(--border, #e3e3e8); background: var(--bg, transparent); }

/* SVG diagrams: full width on a plain background. */
.media-svg { display: block; width: 100%; }
.media-svg img { display: block; max-width: 100%; border: 1px solid var(--border, #e3e3e8);
  border-radius: var(--radius-sm, 6px); padding: 12px; background: var(--bg, #fff); }

/* Two or more images: a grid of square tiles. */
.media-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 6px; }
.media-gallery .media-image img { width: 100%; height: 100%; max-height: none; aspect-ratio: 1; object-fit: cover; }
.media-gallery .media-image { transition: transform 0.15s ease; }
.media-gallery .media-image:hover { transform: scale(1.02); }

/* Video: the player at its own aspect ratio, with a full-screen button. */
.media-video { position: relative; max-width: 100%; width: fit-content; }
.media-video video { display: block; max-width: 100%; max-height: 420px; border-radius: var(--radius-sm, 6px);
  background: #000; }
.media-expand { position: absolute; top: 8px; right: 8px; width: 30px; height: 30px; display: grid; place-items: center;
  border: 0; border-radius: var(--radius-sm, 6px); background: rgba(0, 0, 0, 0.55); color: #fff;
  font-size: 16px; line-height: 1; cursor: pointer; opacity: 0; transition: opacity 0.15s ease; }
.media-video:hover .media-expand, .media-expand:focus-visible { opacity: 1; }
@media (hover: none) { .media-expand { opacity: 1; } }
.media-unplayable { padding: 10px 12px; border: 1px dashed var(--border, #e3e3e8); border-radius: var(--radius-sm, 6px);
  color: var(--text-dim, #6b6b78); font-size: 13px; }

.media-audio audio { display: block; width: 100%; max-width: 480px; }

/* PDF: a card that opens the viewer. */
button.media-pdf { display: inline-flex; align-items: center; gap: 10px; max-width: 100%; padding: 8px 12px;
  border: 1px solid var(--border, #e3e3e8); border-radius: var(--radius-sm, 6px);
  background: var(--surface, #fff); cursor: pointer; }
button.media-pdf:hover { border-color: var(--accent, #c92a2a); }
.media-pdf-icon { flex: none; padding: 2px 6px; border-radius: 4px; background: var(--accent, #c92a2a); color: #fff;
  font-size: 11px; font-weight: 700; letter-spacing: 0.04em; }
.media-pdf-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-pdf-hint { flex: none; color: var(--accent, #c92a2a); font-size: 13px; }

.media-inline-image { cursor: zoom-in; }

/* Attachment chips of a question: a video thumbnail like an image's. */
.msg .attachment-chip video { width: 32px; height: 32px; object-fit: cover; border-radius: 3px; background: #000; }
.msg .attachment-chip.media-item { cursor: zoom-in; }

/* A file the agent made that was not delivered (too large). */
.output-file-chip-skipped { color: var(--text-dim, #6b6b78); cursor: help; border-style: dashed; }
.output-file-chip-skipped:hover { transform: none; border-color: var(--border, #e3e3e8); }

/* ---- The media viewer ---- */
.media-viewer { position: fixed; inset: 0; z-index: 1000; display: none; }
.media-viewer.open { display: block; }
.media-viewer-backdrop { position: absolute; inset: 0; background: rgba(8, 7, 16, 0.92); }
.media-viewer-bar { position: absolute; top: 0; left: 0; right: 0; z-index: 2; display: flex; align-items: center;
  gap: 14px; padding: 10px 16px; color: #fff; font-size: 13px;
  background: linear-gradient(rgba(0, 0, 0, 0.55), transparent); }
.media-viewer-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.media-viewer-count { color: rgba(255, 255, 255, 0.7); font-variant-numeric: tabular-nums; }
.media-viewer-bar a { color: #fff; text-decoration: underline; text-underline-offset: 2px; white-space: nowrap; }
.media-viewer-close { border: 0; background: rgba(255, 255, 255, 0.12); color: #fff; border-radius: var(--radius-sm, 6px);
  width: 32px; height: 32px; font-size: 15px; cursor: pointer; }
.media-viewer-close:hover { background: rgba(255, 255, 255, 0.24); }
.media-viewer-stage { position: absolute; inset: 52px 56px 20px; display: flex; align-items: center; justify-content: center; }
.media-viewer-media { max-width: 100%; max-height: 100%; border-radius: 4px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5); }
.media-viewer-image, .media-viewer-svg { object-fit: contain; cursor: zoom-in; }
.media-viewer-svg { background: #fff; padding: 16px; }
/* A video fills the stage (scaled, letterboxed); images keep their own size. */
.media-viewer-video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.media-viewer-pdf { width: 100%; height: 100%; border: 0; background: #fff; }
/* Zoomed: the image at its own size, scrollable. */
.media-viewer-stage.zoomed { overflow: auto; align-items: flex-start; justify-content: flex-start; }
.media-viewer-stage.zoomed .media-viewer-media { max-width: none; max-height: none; cursor: zoom-out; }
.media-viewer-nav { position: absolute; top: 50%; z-index: 2; transform: translateY(-50%); width: 44px; height: 64px;
  border: 0; border-radius: var(--radius-sm, 6px); background: rgba(255, 255, 255, 0.1); color: #fff;
  font-size: 34px; line-height: 1; cursor: pointer; }
.media-viewer-nav:hover { background: rgba(255, 255, 255, 0.22); }
.media-viewer-nav[hidden] { display: none; }
.media-viewer-prev { left: 6px; }
.media-viewer-next { right: 6px; }

@media (max-width: 700px) {
  /* Previous/Next sit under the stage, clear of the video's controls. */
  .media-viewer-stage { inset: 52px 0 68px; }
  .media-viewer-nav { top: auto; bottom: 12px; transform: none; height: 44px; }
  .media-viewer-open { display: none; }
  .media-gallery { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
}
