/* The tiles of the Files panel on a delivery (js/upload-tiles.js) and of
   the client's page (recipient.css builds on them): the grid, a tile with
   its check, its label and its progress line, and the producer's caption
   under it. Loaded by index.html right after uploads.css, whose panel
   rules come first on purpose.

   Cell layout:  [ tile 3:2 with check, label, bar ]
                 [ name                            ]
                 [ size, or what went wrong    [x] ] */

:root {
  --up-tile: 124px;         /* narrowest a tile may get; the grid fills the rest */
  --up-cell-height: 129px;  /* narrowest tile + caption (and its 4px of air under the tile), held for tiles skipped off screen */
  --up-check-size: 22px;
  --up-remove-size: 24px;
}

@media (max-width: 820px) {
  :root {
    --up-tile: 96px;
    --up-cell-height: 110px;
  }
}

/* --- the grid and its tiles ----------------------------------------- */

.wgrid.up-grid {
  flex: none;
  grid-template-columns: repeat(auto-fill, minmax(var(--up-tile), 1fr));
  gap: var(--space-3);
  padding: 0;
  overflow: visible;
}

/* Thousands of tiles: the browser skips drawing the ones off screen. */
.up-cell {
  min-width: 0;
  content-visibility: auto;
  contain-intrinsic-block-size: auto var(--up-cell-height);
  /* Tab must not leave the focused tile under the sticky summary bar
     (bar height and its gap). */
  scroll-margin-bottom: 96px;
}

.up-tile {
  overflow: hidden;
  border-radius: var(--radius-control);
  background: var(--sunken);
}
/* A hairline inside the picture's edge keeps a pale photo off the paper. */
.up-tile::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  border-radius: inherit;
  box-shadow: inset 0 0 0 1px var(--photo-edge);
  opacity: .5;
  pointer-events: none;
}

/* Over the picture, inside the tile. Only a failed file draws here: a
   chosen file is told by its check, not by a ring (the focus ring is the
   toggle's own outline). */
.up-tile::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
}
.up-cell.is-failed .up-tile::after { box-shadow: inset 0 0 0 2px var(--red); }

/* The picture of a file already in the delivery is a button that opens the
   viewer (js/delivery-viewer.js): the whole tile, with nothing of a button
   drawn. Its focus ring is drawn inside, where the tile does not clip it. */
.up-view {
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  cursor: zoom-in;
}
.up-view:focus-visible { outline-offset: -2px; }

/* A thumbnail fades in where the grey tile stood, instead of popping. */
.up-tile .up-thumb {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  animation: fade var(--dur-slow) var(--ease-out);
}

.up-generic {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  width: 100%;
  height: 100%;
  background: var(--sunken);
  color: var(--mute);
}
.up-generic svg { width: 20px; height: 20px; }
.up-generic b {
  font: 500 var(--text-xs)/16px var(--font-sans);
  letter-spacing: .06em;
  color: var(--ink2);
}

/* A file left out of this upload: grey and faint, in both themes. The
   fade (180ms) shows which tile a click just changed. */
.up-thumb,
.up-generic { transition: opacity var(--dur) var(--ease-out); }
.up-cell.is-off .up-thumb,
.up-cell.is-off .up-generic {
  opacity: .35;
  filter: grayscale(1);
}

.up-toggle {
  position: absolute;
  inset: 0;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

/* A left-out file's check is an empty rounded square, a chosen file's is
   the accent with a tick that contrasts with it in both themes. The tick
   pops in (scale .6 to 1, 160ms) so a choice is seen where it was made. */
.up-check {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  z-index: 2;
  display: grid;
  place-items: center;
  width: var(--up-check-size);
  height: var(--up-check-size);
  border: 1.5px solid var(--on-photo);
  border-radius: var(--radius-s);
  background: color-mix(in srgb, var(--veil) 45%, transparent);
  box-shadow: 0 0 0 1px var(--photo-edge);
  color: transparent;
  transition: opacity var(--dur-fast) var(--ease-out), background-color var(--dur-fast), border-color var(--dur-fast);
}
.up-check svg { width: var(--space-3); height: var(--space-3); stroke-width: 2.8; transform: scale(.6); opacity: 0; transition: transform 160ms var(--ease-out), opacity 160ms var(--ease-out); }
.up-cell.is-selected .up-check {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}
.up-cell.is-selected .up-check svg { transform: none; opacity: 1; }

/* While every file is chosen the checks say nothing, so they hide until
   the pointer is over a tile. Touch has no hover: its checks always show.
   upload-view.js adds .has-deselected when any file is left out. */
@media (hover: hover) {
  .up-grid:not(.has-deselected) .up-cell:not(:hover):not(:focus-within) .up-check { opacity: 0; }
}

/* The label over a photo: the same words and meanings as everywhere, as a
   solid fill with white words, because a tint would take the photo's
   colour. Neutral is the dark veil. */
.up-tag,
.up-tag[data-tone] {
  height: 20px;
  line-height: 20px;
  padding: 0 6px;
  background: var(--veil);
  color: var(--on-photo);
  box-shadow: none;
}
.up-tag[data-tone=ok],
.up-tag[data-tone=done] { background: var(--solid-success); }
.up-tag[data-tone=busy] { background: var(--solid-info); }
.up-tag[data-tone=attention] { background: var(--solid-warning); }
.up-tag[data-tone=failed] { background: var(--solid-danger); }
.up-tag {
  position: absolute;
  z-index: 2;
  top: var(--space-2);
  right: var(--space-2);
  max-width: calc(100% - var(--up-check-size) - 3 * var(--space-2));
  pointer-events: none;
}

.up-bar {
  position: absolute;
  z-index: 2;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--up-bar-height);
  border-radius: 0;
  background: color-mix(in srgb, var(--veil) 40%, transparent);
}

.up-retry {
  position: absolute;
  z-index: 2;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

/* --- the caption under a tile ----------------------------------------- */

.up-cap {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding-top: var(--space-1);
  font-size: var(--text-m);
}
.up-name,
.up-error {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.up-name { font-weight: 500; }
.up-error { color: var(--red); font-size: var(--text-s); }

/* The producer's caption: the name on the whole width of the tile, then a
   row with the size and, for a file already in the delivery, the remove
   button. (Name, size and remove on one line would leave a 148px tile 58px
   for the name, and every caption would read "IMG_200...". See also
   nameHtml in upload-tiles.js.) The second row is as tall as the button
   whether or not there is one, so staged and saved cells are equally tall,
   which --up-cell-height relies on. */
.up-cap-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto var(--up-remove-size);
  column-gap: var(--space-2);
  align-items: center;
}
.up-cap-row .up-name { grid-column: 1 / -1; grid-row: 1; display: flex; font-weight: 400; line-height: 18px; color: var(--ink); }
.up-cap-row .s { grid-column: 1; grid-row: 2; font-size: var(--text-s); line-height: 16px; }
.up-cap-row .up-error { grid-column: 1 / -1; grid-row: 2; line-height: 16px; }

/* The head gives way to the ellipsis, the end of the name never does. */
.up-name-head { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: pre; }
.up-name-tail { flex: none; white-space: pre; }

/* Remove lives in the caption, visible on every device. Hidden over the
   photo until hover it would be an invisible tab stop on every tile, and
   a wall of dark circles on a phone. The ::before makes the target bigger
   than the x. */
.btn.up-remove {
  position: relative;
  grid-column: 2;
  grid-row: 2;
  width: var(--up-remove-size);
  height: var(--up-remove-size);
  padding: 0;
  border: 0;
  color: var(--mute);
}
.btn.up-remove::before { content: ""; position: absolute; inset: calc(-1 * var(--space-2)) calc(-1 * var(--space-1)); }
.btn.up-remove svg { width: var(--icon-s); height: var(--icon-s); }
.btn.up-remove:hover { color: var(--red); background: var(--danger-bg); }

/* --- phone ------------------------------------------------------------- */

@media (max-width: 820px) {
  .wgrid.up-grid { gap: var(--space-2); }

  /* On a 96px tile a word like "Resuming" would run under the check mark
     and past the edge; along the bottom it has the tile's width. */
  .up-tag {
    top: auto;
    right: auto;
    bottom: calc(var(--space-2) + var(--up-bar-height));
    left: var(--space-2);
    max-width: calc(100% - 2 * var(--space-2));
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}
