/* ==========================================================================
   The files in the dashboard's chat (js/chat-files.js): a card for each,
   which opens the viewer (css/file-viewer.css). Ported from the macOS app. A picture or a video is a
   tile of its own; anything else a card with a small face (a PDF's first
   page, or its kind in letters), its name, its kind and size. No icons.
   ========================================================================== */

.chat-files { display: flex; flex-wrap: wrap; gap: var(--space-2); margin: var(--space-1) 0 var(--space-3); }
.message.user .chat-files { justify-content: flex-end; margin: var(--space-2) 0 0; }
.message.assistant .steps + .chat-files { margin-top: var(--space-2); }
.message.files-row { margin-bottom: var(--space-4); }

.chat-file-item { display: flex; flex-direction: column; gap: var(--space-1); max-width: 100%; min-width: 0; }
/* A card is one width, whatever its name (a long one is cut short with an ellipsis, its whole name on hover). */
/* (A width and a max-width, not min(): a person's files sit in a box as wide as they are, where a % has nothing to go by.) */
.chat-file-item:not(.is-image, .is-video, .is-audio), .chat-file-item.is-audio.is-gone { width: 264px; max-width: 100%; }
.message.user .chat-file-item { align-items: flex-end; }

.chat-file {
  display: flex; align-items: center; gap: 10px;
  width: 100%; min-width: 0; box-sizing: border-box; padding: 8px 12px 8px 8px;
  font: inherit; color: var(--text); text-align: left;
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  cursor: pointer;
  transition: background-color var(--duration-fast, 120ms) ease, border-color var(--duration-fast, 120ms) ease;
}
.chat-file:hover { background: var(--bg-surface-hover); border-color: var(--border-hover); }
.chat-file:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.chat-file:disabled { cursor: default; opacity: 0.6; }
.chat-file:disabled:hover { background: var(--bg-surface); border-color: var(--border); }

.chat-file-thumb {
  position: relative; flex: none; width: 44px; height: 44px; overflow: hidden;
  display: grid; place-items: center;
  background: var(--bg-input); border: 1px solid var(--border-light); border-radius: var(--radius-md);
}
.chat-file-thumb img, .chat-file-thumb video { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.chat-file-thumb.is-page { background: #fff; }
.chat-file-thumb.is-page img { object-position: top; }
.chat-file-ext { font-family: var(--font-mono); font-size: 10px; font-weight: 600; letter-spacing: 0.04em; color: var(--text-secondary); }

.chat-file-text { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.chat-file-name { font-size: var(--text-sm); font-weight: 500; line-height: 1.35; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-file-meta { font-size: var(--text-xs); color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* A picture or a video: the tile is the thing itself (its name is on it for screen readers and on hover). */
.chat-file-item:is(.is-image, .is-video) .chat-file { width: auto; padding: 0; overflow: hidden; }
.chat-file-item:is(.is-image, .is-video) .chat-file-thumb { width: 220px; max-width: 100%; height: 156px; border: 0; border-radius: 0; }
.chat-file-item:is(.is-image, .is-video) .chat-file-text { display: none; }
.chat-file-item:is(.is-image, .is-video).is-gone .chat-file-text { display: flex; padding: 8px 12px; }
.chat-file-item:is(.is-image, .is-video).is-gone .chat-file-thumb { display: none; }
.chat-file-play {
  position: absolute; inset: 0; margin: auto; width: 40px; height: 40px; border-radius: 50%;
  background: rgba(0, 0, 0, 0.55); pointer-events: none;
}
.chat-file-play::after {
  content: ""; position: absolute; left: 16px; top: 12px;
  border-style: solid; border-width: 8px 0 8px 13px; border-color: transparent transparent transparent #fff;
}

.chat-file-caption { margin: 0; max-width: 264px; font-size: var(--text-xs); line-height: 1.45; color: var(--text-muted); overflow-wrap: anywhere; }
.message.user .chat-file-caption { text-align: right; }

/* A sound: the waveform player, in the viewer's dark look whatever the theme. */
.chat-files .of-wave.is-compact {
  --text: #ececec; --text-secondary: #a8a8a0; --text-muted: #9a9a92; --border: #3a3935;
  width: 288px; max-width: 100%; padding: 8px 10px; border-radius: var(--radius-lg);
  color: var(--text); background: #2b2a27; border: 1px solid var(--border);
}

@media (max-width: 480px) {
  .chat-file-item:is(.is-image, .is-video) .chat-file-thumb { width: 180px; height: 132px; }
}
