/* The attachment look agreed with Felix on 4 Nov 2026 (2:15 PM SGT).
   Pictures: small same-height thumbnails that wrap, sit to the right, above the message. Everything else: one compact chip.
   Annotations: a small chip with a pen and a count; hovering it shows each selected text and comment with edit and delete.
   The message box and the sent message use the same rules. Phone sizes are the :root values in the media block. */
:root {
  --attach-thumb-h: 56px;
  --attach-chip-h: 28px;
  --attach-chip-max: 190px;
  --attach-gap: 6px;
}
@media (max-width: 600px) {
  :root {
    --attach-thumb-h: 44px;
    --attach-chip-max: 150px;
    --attach-gap: 4px;
  }
}

/* The row of attachments above a message, aligned to the left (Felix, 4 Nov 3:14 PM SGT). */
.attachment-list, .msg-wrapper > .attachment-list {
  display: flex; flex-direction: row; flex-wrap: wrap; justify-content: flex-start; align-items: flex-start;
  gap: var(--attach-gap); width: 100%; max-width: 100%; box-sizing: border-box; margin: 0 0 6px;
}
.team-msg:not(.team-user) .attachment-list { justify-content: flex-start; }
#image-preview { gap: var(--attach-gap); align-items: flex-end; }
#image-preview .pending-file-preview { min-width: 0; min-height: 0; }

/* Picture thumbnail */
.attachment-card-thumb, #image-preview .attachment-card-thumb {
  display: inline-flex; flex-direction: row; width: auto; max-width: none; height: var(--attach-thumb-h);
  border: 1px solid var(--border); border-radius: 8px; overflow: hidden; box-sizing: content-box;
}
.attachment-card.attachment-card-thumb .attachment-media, #image-preview .attachment-card.attachment-card-thumb .attachment-media {
  display: block; width: auto; height: var(--attach-thumb-h); max-height: var(--attach-thumb-h);
  max-width: calc(var(--attach-thumb-h) * 1.5); min-width: calc(var(--attach-thumb-h) * 0.6);
  object-fit: cover; border: 0; border-radius: 0; cursor: zoom-in;
}

/* Compact chip: icon, name, size or length */
.attachment-card-chip, #image-preview .attachment-card-chip {
  display: inline-flex; flex-direction: row; align-items: center; width: auto; max-width: var(--attach-chip-max); min-width: 0;
}
.attachment-card-chip .pdf-attachment, #image-preview .attachment-card-chip .pdf-attachment {
  display: inline-flex; align-items: center; gap: 6px; width: auto; max-width: var(--attach-chip-max); min-width: 0;
  height: var(--attach-chip-h); padding: 0 10px 0 6px; box-sizing: border-box; border-radius: calc(var(--attach-chip-h) / 2); font-size: 12px;
}
.attachment-card-chip .pdf-attachment-icon, #image-preview .attachment-card-chip .pdf-attachment-icon {
  flex: 0 0 16px; width: 16px; height: 16px; background: transparent; border-radius: 0; font-size: 0;
}
.attachment-card-chip .pdf-attachment-icon svg, #image-preview .attachment-card-chip .pdf-attachment-icon svg { width: 14px; height: 14px; }
.attachment-card-chip .pdf-attachment-name, #image-preview .attachment-card-chip .pdf-attachment-name {
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; opacity: 1;
}
.attachment-card-chip .pdf-attachment-size { flex: none; font-size: 11px; opacity: 0.55; }
.attachment-card .attachment-media[hidden], .attachment-card audio.attachment-media[hidden], .attachment-card video.attachment-media[hidden] { display: none; }
/* A voice note or video opens its player under the chip when the chip is tapped */
.attachment-card-chip.attachment-card-playing { flex-direction: column; align-items: stretch; max-width: min(300px, 100%); }
.attachment-card-chip.attachment-card-playing .attachment-media { width: 100%; max-height: 160px; }
.attachment-card-chip .attachment-unavailable { display: none; }
.attachment-card-chip .pdf-attachment[aria-label^="File unavailable"] { border-color: var(--pc07-preserved-paint-1); }

/* Pasted-text card in a sent message: the same chip */
.sent-paste-card { height: var(--attach-chip-h); padding: 0 10px; margin: 0 2px; border-radius: calc(var(--attach-chip-h) / 2); max-width: var(--attach-chip-max); box-sizing: border-box; font-size: 12px; }
.sent-paste-card .sent-paste-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Chips in the queue list */
#durable-conversation-queue .queue-attachment-chip { height: var(--attach-chip-h); box-sizing: border-box; border-radius: calc(var(--attach-chip-h) / 2); max-width: var(--attach-chip-max); }

/* Annotation chip: small, a pen and a count; the quoted text is in the hover card */
.response-annotation-pending, .response-annotation-sent,
#image-preview .response-annotation-pending, .msg.user .response-annotation-sent, .msg.user .response-annotation-sent:first-child {
  position: relative; display: inline-flex; width: auto; max-width: var(--attach-chip-max); margin: 0; padding: 0; background: none; border: 0; box-shadow: none;
}
.response-annotation-pending .response-annotation-pending__open, #image-preview .response-annotation-pending .response-annotation-pending__open,
.response-annotation-sent .response-annotation-sent__open, .msg.user .response-annotation-sent .response-annotation-sent__open {
  display: inline-flex; align-items: center; flex-wrap: nowrap; gap: 6px; width: auto; max-width: 100%; height: var(--attach-chip-h);
  padding: 0 10px 0 6px; box-sizing: border-box; border-radius: calc(var(--attach-chip-h) / 2); white-space: nowrap; font-size: 12px;
}
.response-annotation-pending .response-annotation-pending__icon, #image-preview .response-annotation-pending .response-annotation-pending__icon,
.response-annotation-sent .response-annotation-sent__icon, .msg.user .response-annotation-sent .response-annotation-sent__icon {
  flex: 0 0 16px; width: 16px; height: 16px; background: transparent; border-radius: 0;
}
.response-annotation-pending__icon svg, .response-annotation-sent__icon svg { width: 14px; height: 14px; }
.response-annotation-pending .response-annotation-pending__preview, #image-preview .response-annotation-pending .response-annotation-pending__preview,
.response-annotation-sent .response-annotation-sent__preview, .msg.user .response-annotation-sent .response-annotation-sent__preview { display: none; }
.response-annotation-pending .pdf-attachment-name, .response-annotation-sent .pdf-attachment-name { font-size: 12px; max-width: none; }

/* The hover card */
.annotation-hover-card {
  display: none; position: absolute; bottom: 100%; left: 0; z-index: 60; width: max-content; max-width: min(290px, calc(100vw - 24px));
  box-sizing: border-box; padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-raised, var(--pc07-preserved-paint-2));
  color: var(--text, var(--pc07-preserved-paint-3)); font-size: 12px; line-height: 1.4; text-align: left; white-space: normal; box-shadow: 0 6px 18px var(--pc07-preserved-paint-4);
}
/* the hover card opens from the left edge of its chip */
.response-annotation-pending:hover .annotation-hover-card, .response-annotation-pending:focus-within .annotation-hover-card,
.response-annotation-sent:hover .annotation-hover-card, .response-annotation-sent:focus-within .annotation-hover-card { display: block; }
.annotation-hover-item + .annotation-hover-item { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.annotation-hover-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.annotation-hover-card b { display: block; font-weight: 500; opacity: 0.6; }
.annotation-hover-quote, .annotation-hover-comment { overflow-wrap: anywhere; margin-bottom: 4px; }
.annotation-hover-actions { display: inline-flex; gap: 2px; }
.annotation-hover-actions button { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; padding: 0; border: 0; border-radius: 6px; background: transparent; color: inherit; cursor: pointer; }
.annotation-hover-actions button:hover, .annotation-hover-actions button:focus-visible { background: var(--pc07-preserved-paint-5); }
.annotation-hover-actions svg { width: 14px; height: 14px; }

/* The sent annotation chip sits above its message, left aligned, like the picture row (the chip stays inside the bubble in the DOM) */
.msg.user:has(> .response-annotation-sent) { position: relative; margin-top: calc(var(--attach-chip-h) + 8px); }
.msg.user > .response-annotation-sent, .msg.user > .response-annotation-sent:first-child { position: absolute; left: 0; bottom: 100%; margin: 0 0 4px; }
/* Opened by a tap or click on the chip (a phone has no hover) */
.response-annotation-pending.is-open .annotation-hover-card, .response-annotation-sent.is-open .annotation-hover-card { display: block; }

/* ===== Many attachments (Felix, 4 Nov 2026, 7:49 PM SGT; PC-2026-11-04-101) =====
   The message box shows one row and a sent message two; the rest folds into a "+N" tile (attachment-overflow.js) that opens the grid of every file:
   a bottom sheet on a phone, a centred dialog on a desktop. The viewer steps through pictures (lightbox.js). */
.attach-folded { display: none !important; }
.attach-more-tile {
  position: relative; flex: none; display: inline-flex; align-items: center; justify-content: center;
  height: calc(var(--attach-thumb-h) + 2px); min-width: calc(var(--attach-thumb-h) + 2px); padding: 0 8px; box-sizing: border-box;
  border: 1px solid var(--border); border-radius: 8px; overflow: hidden; cursor: pointer;
  background: var(--surface) center / cover no-repeat; color: var(--text); font-family: inherit;
}
.attach-more-tile b { position: relative; font-size: 15px; font-weight: 600; line-height: 1; letter-spacing: 0.2px; }
.attach-more-tile.has-bg { color: var(--k-fg-005); }
.attach-more-tile.has-bg::before { content: ""; position: absolute; inset: 0; background: var(--k-fg-004); opacity: 0.55; }
.attach-more-tile:hover { border-color: var(--k-bd-007); }
.attach-more-tile:focus-visible { outline: 2px solid var(--k-bd-007); outline-offset: 2px; }

#attach-backdrop { position: fixed; inset: 0; z-index: 1000; background: var(--k-fx-033); display: none; }
#attach-backdrop.open { display: block; }
#attach-sheet {
  position: fixed; z-index: 1001; left: 0; right: 0; bottom: 0; max-height: 78vh; max-height: 78dvh;
  display: none; flex-direction: column; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-bottom: 0; border-radius: 14px 14px 0 0; box-shadow: 0 -8px 28px var(--k-fx-001);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
#attach-sheet.open { display: flex; animation: attach-sheet-in 180ms ease-out; }
@keyframes attach-sheet-in { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (min-width: 601px) {
  #attach-sheet { left: 50%; right: auto; bottom: auto; top: 50%; width: min(620px, calc(100vw - 48px)); max-height: 80vh; transform: translate(-50%, -50%); border-bottom: 1px solid var(--border); border-radius: 14px; }
  #attach-sheet.open { animation: attach-dialog-in 160ms ease-out; }
  @keyframes attach-dialog-in { from { opacity: 0; transform: translate(-50%, -48%); } to { opacity: 1; transform: translate(-50%, -50%); } }
}
@media (prefers-reduced-motion: reduce) { #attach-sheet.open { animation: none; } }
#attach-sheet header { flex: none; display: flex; align-items: center; gap: 8px; padding: 10px 8px 10px 16px; border-bottom: 1px solid var(--border); }
#attach-sheet h2 { flex: 1; margin: 0; font-size: 15px; font-weight: 600; }
#attach-sheet h2 small { font-weight: 400; color: var(--text-dim); margin-left: 6px; }
.attach-sheet-btn { min-width: 44px; height: 44px; padding: 0 12px; border: 0; border-radius: 8px; background: none; color: var(--text); font: inherit; font-size: 14px; cursor: pointer; }
.attach-sheet-btn[hidden] { display: none; }
.attach-sheet-btn:hover { background: var(--k-bg-026); }
.attach-sheet-btn.danger { color: var(--danger); }
.attach-sheet-btn.primary { color: var(--accent); font-weight: 600; }
.attach-sheet-btn:focus-visible { outline: 2px solid var(--k-bd-007); outline-offset: -2px; }
.attach-grid {
  --attach-thumb-h: 104px;
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 16px 16px 20px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 16px 12px; align-content: start;
}
@media (max-width: 600px) { .attach-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 10px; padding: 14px 14px 18px; } }
.attach-grid-item { position: relative; aspect-ratio: 1; min-width: 0; }
.attach-grid-item.is-chip { aspect-ratio: auto; grid-column: 1 / -1; align-self: center; }
.attach-grid .attachment-card.attachment-card-thumb { width: 100%; height: 100%; box-sizing: border-box; display: flex; cursor: zoom-in; }
.attach-grid .attachment-card.attachment-card-thumb .attachment-media { width: 100%; height: 100%; max-height: none; max-width: none; min-width: 0; }
.attach-grid .attachment-card-chip { max-width: none; width: 100%; }
.attach-grid .attachment-card-chip .pdf-attachment { max-width: none; width: 100%; height: 44px; border-radius: 22px; font-size: 13px; }
.attach-grid .attachment-card-chip .pdf-attachment-name { font-size: 13px; }
.attach-grid .remove-img { position: absolute; top: -22px; right: -22px; width: 44px; height: 44px; padding: 0; z-index: 1; border: 0; background: transparent; color: transparent; font-size: 0; cursor: pointer; }
.attach-grid .remove-img::after { content: "x"; position: absolute; top: 12px; right: 12px; width: 20px; height: 20px; border-radius: 50%; background: var(--danger); color: var(--k-fg-005); font-size: 12px; display: flex; align-items: center; justify-content: center; }
.attach-grid .remove-img:focus-visible { outline: 2px solid var(--k-bd-007); outline-offset: 2px; }

/* The viewer: previous, next and a counter when the message has several pictures */
#lightbox-overlay .lb-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 48px; height: 64px; border: 0; background: var(--k-fx-001); color: var(--k-fg-005); font-size: 30px; line-height: 1; cursor: pointer; border-radius: 10px; display: none; align-items: center; justify-content: center; }
#lightbox-overlay.gallery .lb-nav { display: flex; }
#lightbox-overlay #lb-prev { left: 10px; }
#lightbox-overlay #lb-next { right: 10px; }
#lightbox-overlay .lb-nav:disabled { opacity: 0.25; cursor: default; }
#lightbox-overlay .lb-nav:focus-visible { outline: 2px solid var(--k-fg-005); outline-offset: 2px; }
#lb-count { position: absolute; top: 24px; left: 20px; color: var(--k-fg-005); font-size: 14px; opacity: 0.85; display: none; }
#lightbox-overlay.gallery #lb-count { display: block; }
#lightbox-overlay #lightbox-img { touch-action: pan-y; }
