/* U3 — attachment cards in the composer and in sent messages.
   Grayscale surfaces; status colors appear only for a real problem. The
   preview tile stays white in both themes, like a page. */
:root {
  --att-tile: #ffffff;
  --att-tile-ink: #2b2b2b;
  --att-tile-muted: #6b6b6b;
  --att-bar: #1e1e1e;
  --att-bar-ink: #f2f2f2;
  --att-edge: rgba(255, 255, 255, 0.12);
  --att-card-h: 124px;
  --att-card-w: 184px;
  --att-bar-h: 36px;
}
:root[data-theme="light"] {
  --att-bar: #f2f2f2;
  --att-bar-ink: #000000;
  --att-edge: rgba(0, 0, 0, 0.12);
}

/* ---------- composer tray ---------- */
.composer .att-tray { display: flex; flex-direction: column; gap: 6px; min-width: 0; max-width: 100%; }
.composer .att-tray[hidden] { display: none; }
.att-row.file-chips {
  display: flex; flex-wrap: nowrap; gap: 10px; max-width: none; margin: 0; padding: 2px 2px 4px;
  overflow-x: auto; overflow-y: hidden; scroll-snap-type: x proximity; overscroll-behavior-x: contain;
  scrollbar-width: thin; -webkit-overflow-scrolling: touch;
}
.att-caption { display: flex; align-items: center; gap: 6px; margin: 0; padding: 0 2px; font-size: 11.5px; line-height: 1.3; color: var(--ink-3); }
.att-caption[hidden] { display: none; }
.att-caption-icon { display: inline-flex; flex: none; }
.att-caption svg { width: 12px; height: 12px; flex: none; }
.att-caption.is-alert { color: var(--red); }

/* ---------- composer card ---------- */
.att-row .att-card.file-chip {
  position: relative; flex: none; display: flex; flex-direction: column; align-items: stretch; gap: 0;
  width: var(--att-card-w); height: var(--att-card-h); max-width: none; padding: 0;
  border-radius: 14px; overflow: hidden; border: 1px solid var(--att-edge);
  background: var(--att-bar); color: var(--att-bar-ink); font-size: 12px; scroll-snap-align: start;
  transition: opacity 0.15s ease;
}
.att-row .att-card.att-image { width: var(--att-card-h); }
.att-row .att-card.att-image .att-bar { display: none; }
.att-row .att-card.is-removing { opacity: 0.45; pointer-events: none; }

.att-tile {
  position: relative; display: block; flex: 1 1 auto; min-height: 0; width: 100%;
  margin: 0; padding: 0; border: 0; border-radius: 0; overflow: hidden;
  background: var(--att-tile); color: var(--att-tile-ink); font: inherit; text-align: left;
}
button.att-tile { cursor: pointer; }
button.att-tile:focus-visible { outline: 2px solid var(--att-tile-ink); outline-offset: -3px; }
.att-img { display: block; width: 100%; height: 100%; object-fit: cover; }
.att-lines {
  margin: 0; padding: 10px 12px 0; height: 100%; overflow: hidden; white-space: pre;
  font: 450 9.5px/1.45 var(--font); color: #3b3b3b;
  -webkit-mask-image: linear-gradient(to bottom, #000 58%, transparent);
  mask-image: linear-gradient(to bottom, #000 58%, transparent);
}
.att-doc { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--att-tile-muted); }
.att-doc svg { width: 26px; height: 26px; margin-bottom: 4px; }
.att-doc-type { font-size: 12px; font-weight: 650; color: var(--att-tile-ink); }
.att-doc-size { font-size: 11px; }

.att-bar { flex: none; height: var(--att-bar-h); display: flex; align-items: center; gap: 7px; min-width: 0; padding: 0 10px; background: var(--att-bar); color: var(--att-bar-ink); }
.att-row .att-card .att-bar svg { width: 14px; height: 14px; flex: none; opacity: 0.8; }
.att-row .att-card .att-name { flex: 1; min-width: 0; max-width: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; font-weight: 550; }

.att-row .att-card .att-x {
  position: absolute; top: 6px; right: 6px; z-index: 3; width: 24px; height: 24px; padding: 0;
  display: grid; place-items: center; border-radius: 50%; cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.24); background: rgba(0, 0, 0, 0.72); color: #ffffff;
}
.att-row .att-card .att-x svg { width: 12px; height: 12px; opacity: 1; }
.att-row .att-card .att-x:hover { background: #000000; color: #ffffff; }
.att-row .att-card .att-x:focus-visible { outline: 2px solid var(--ink); outline-offset: 1px; }

/* Uploading: the real preview, blurred, with a ring driven by upload bytes. */
.att-tile > * { transition: filter 0.45s ease, transform 0.45s ease, opacity 0.45s ease; }
.att-card.is-uploading .att-tile > * { filter: blur(7px) saturate(0.85); transform: scale(1.06); opacity: 0.85; }
.att-progress { position: absolute; left: 0; right: 0; top: 0; bottom: var(--att-bar-h); z-index: 2; display: grid; place-items: center; pointer-events: none; }
.att-image .att-progress { bottom: 0; }
.att-card .att-ring { width: 36px; height: 36px; flex: none; opacity: 1; padding: 3px; border-radius: 50%; background: rgba(0, 0, 0, 0.62); box-shadow: 0 2px 10px rgba(0, 0, 0, 0.22); transform: rotate(-90deg); }
.att-card .att-ring circle { fill: none; stroke-width: 3.4; }
.att-ring-track { stroke: rgba(255, 255, 255, 0.24); }
.att-ring-fill { stroke: #ffffff; stroke-linecap: round; stroke-dasharray: 100; stroke-dashoffset: 100; transition: stroke-dashoffset 0.2s linear; }
.att-card.is-processing .att-ring { animation: att-spin 0.9s linear infinite; }
.att-card.is-processing .att-ring-fill { stroke-dashoffset: 72 !important; }
@keyframes att-spin { from { transform: rotate(-90deg); } to { transform: rotate(270deg); } }

/* Status that keeps a file from reaching the agent. */
.att-badge {
  position: absolute; left: 6px; top: 6px; z-index: 2; max-width: calc(100% - 42px);
  padding: 2px 7px; border-radius: 999px; font-size: 10.5px; font-weight: 650; line-height: 16px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: #fff1d1; color: #5f3d00;
}
.att-row .att-card.warn { border-color: color-mix(in srgb, var(--amber) 55%, transparent); }
.att-row .att-card.bad { border-color: color-mix(in srgb, var(--red) 60%, transparent); }
.att-card.bad .att-badge { background: #ffe0e4; color: #83192a; }

/* Failed upload: say so on the card and offer Retry when it can help. */
.att-row .att-card.is-failed { border-color: color-mix(in srgb, var(--red) 60%, transparent); }
.att-card.is-failed .att-tile > * { filter: blur(3px) grayscale(1); opacity: 0.5; }
.att-fail {
  position: absolute; left: 0; right: 0; top: 0; bottom: var(--att-bar-h); z-index: 2;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px;
  padding: 8px 30px 8px 10px; text-align: center; background: rgba(0, 0, 0, 0.58); color: #ffffff;
}
.att-image .att-fail { bottom: 0; }
.att-fail svg { width: 16px; height: 16px; color: #ff9aa6; flex: none; }
.att-fail-msg { font-size: 11.5px; font-weight: 600; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.att-retry { border: 0; border-radius: 999px; padding: 4px 12px; background: #ffffff; color: #000000; font: 600 11.5px/1.2 var(--font); cursor: pointer; }
.att-retry:focus-visible { outline: 2px solid #ffffff; outline-offset: 2px; }

/* Drop files anywhere on the conversation to attach them. */
.composer-dock .composer.is-drop-target, .composer.is-drop-target { border-style: dashed; border-color: var(--ink-3); background: var(--hover); }

/* Send pressed while files upload: the message waits, then sends. */
.composer.is-waiting-for-uploads .composer-send { position: relative; color: transparent; pointer-events: none; }
.composer.is-waiting-for-uploads .composer-send::after {
  content: ""; position: absolute; inset: 8px; border-radius: 50%;
  border: 2px solid var(--bg); border-right-color: transparent; animation: att-turn 0.8s linear infinite;
}
@keyframes att-turn { to { transform: rotate(360deg); } }

/* ---------- sent messages ---------- */
.att-sent { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; max-width: 100%; margin: 0 0 8px; }
.att-sent-image {
  position: relative; display: block; flex: none; width: 168px; height: 168px; margin: 0; padding: 0;
  border: 1px solid var(--line); border-radius: 16px; overflow: hidden; background: var(--panel-2); cursor: zoom-in;
}
.att-sent-image img { display: block; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity 0.25s ease; }
.att-sent-image.is-loaded img { opacity: 1; }
.att-sent-image:not(.is-loaded)::before {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(100deg, transparent 30%, var(--hover-2) 50%, transparent 70%) var(--panel-2);
  background-size: 200% 100%; animation: att-shimmer 1.3s linear infinite;
}
.att-sent-image.is-broken::before, .att-sent-image.is-large::before { animation: none; background: var(--panel-2); }
.att-sent-large { position: absolute; inset: 0; z-index: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; color: var(--ink-3); font-size: 11.5px; }
.att-sent-large svg { width: 26px; height: 26px; }
.att-sent-image:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.att-sent.has-single-image .att-sent-image { --att-ratio: 1.3333; height: auto; aspect-ratio: var(--att-ratio); width: min(320px, 100%, calc(360px * var(--att-ratio))); }
@keyframes att-shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

.att-sent-file {
  display: flex; align-items: center; gap: 10px; min-width: 0; width: min(360px, 100%);
  padding: 8px 10px 8px 8px; border: 1px solid var(--line-2); border-radius: 14px; background: var(--panel);
}
.att-sent-icon { flex: none; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 10px; background: var(--att-tile); color: #3b3b3b; box-shadow: inset 0 0 0 1px var(--line-2); }
.att-sent-icon svg { width: 20px; height: 20px; }
.att-sent-copy { flex: 1; display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.att-sent-copy .att-sent-name { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; overflow-wrap: normal; font-size: 13.5px; font-weight: 600; }
.att-sent-copy small { color: var(--ink-3); font-size: 11.5px; }
.att-sent-file .file-download-action { flex: none; }

@media (max-width: 680px) {
  :root { --att-card-h: 104px; --att-card-w: 148px; --att-bar-h: 32px; }
  .att-row.file-chips { gap: 8px; }
  .att-lines { padding: 8px 9px 0; font-size: 8.5px; }
  .att-row .att-card .att-name { font-size: 12px; }
  .att-sent-image { width: 132px; height: 132px; }
  .att-sent.has-single-image .att-sent-image { width: min(260px, 100%, calc(300px * var(--att-ratio))); }
  .att-sent-file { width: 100%; }
}
@media (hover: none) {
  .att-row .att-card .att-x { width: 28px; height: 28px; top: 5px; right: 5px; }
}
@media (prefers-reduced-motion: reduce) {
  .att-tile > *, .att-ring-fill, .att-sent-image img { transition: none; }
  .att-card.is-processing .att-ring, .composer.is-waiting-for-uploads .composer-send::after, .att-sent-image:not(.is-loaded)::before { animation: none; }
}
