/* Shared image tiles and filmstrip. Legacy classes are used by selection and ordering;
   image_tile_parity_test.rb protects their markup. Spacing is equal on both axes and outer edges. */

/* @group Knobs and tokens */

/* The column count only concerns the list: not inheriting it means a new
   count restyles one element instead of every tile's subtree. */
@property --image-columns {
  syntax: '<integer>';
  inherits: false;
  initial-value: 1;
}

:root {
  /* An icon tile's side, and the mat and hairline around an icon's photo. */
  --block-image-grid-icon-size: var(--ui-image-icon-size);
  --block-image-grid-frame: calc(var(--ui-space-2) * 2 + 2px);
  /* A frame's fill and hairline, and a selected frame's hairline. */
  --block-image-grid-well: var(--color-image-well);
  --block-image-grid-border: var(--color-image-border);
  --block-image-grid-selected-border: var(--color-link-strong);
  /* The spinner a frame shows until its image loads, and a video's badge. */
  --block-image-grid-spinner-size: calc(var(--ui-space-unit) * 6);
  --block-image-grid-video-badge-size: calc(var(--ui-space-unit) * 16);
  /* A video's duration chip sits this far inside its frame's top-end corner. */
  --block-image-grid-video-chip-inset: var(--ui-space-1);
  /* The hidden glyph's box in a frame's top corner. */
  --block-image-grid-state-size: calc(var(--ui-space-unit) * 6);
  /* A hidden photograph shows faded; a selected one dims under the fill. */
  --block-image-grid-hidden-opacity: 0.4;
  --block-image-grid-selected-opacity: 0.5;
  /* The filmstrip's top inset and the space either side of each frame. */
  --block-image-grid-filmstrip-top: 7px;
  --block-image-grid-filmstrip-gap: 3px;

  /* The working names the grid script (images/libraries/image_grid.js) and
     blocks/link_tile.css read. */
  --image-icon-size: var(--block-image-grid-icon-size);
  --image-frame: var(--block-image-grid-frame);
}

/* The page gutter around the list's content block, matching layout_main.css:
   only a screen's first content block (or the one after its hidden title)
   has it. */
#main .content {
  /* stylelint-disable-next-line length-zero-no-unit -- A length, not 0: calc() subtracts it from lengths. */
  --image-content-inset: 0px;
}

#main .content:first-child,
#main .block_visually_hidden:first-child + .content {
  --image-content-inset: var(--ui-page-gutter);
}

/* Stored Spacing values: List offers 2/8/16, Sets 2/12/24. The gap is twice
   the value on the 4px scale. The list carries it (data-image-spacing), and
   all its outer spacing is the gap too: it replaces the page gutter. */
:is(.images_icon_view, .images_thumbnail_view, .images_detail_view, .image_browse) {
  --image-gap: var(--ui-image-gap-medium);

  margin: 0 calc(var(--image-gap) - var(--image-content-inset, 0px));
  padding: 0 0 var(--image-gap);
}

:is(.images_icon_view, .images_thumbnail_view, .images_detail_view, .image_browse)[data-image-spacing="2"] {
  --image-gap: var(--ui-image-gap-small);
}

:is(.images_icon_view, .images_thumbnail_view, .images_detail_view, .image_browse)[data-image-spacing="12"] {
  --image-gap: var(--ui-space-6);
}

:is(.images_icon_view, .images_thumbnail_view, .images_detail_view, .image_browse)[data-image-spacing="16"] {
  --image-gap: var(--ui-image-gap-large);
}

:is(.images_icon_view, .images_thumbnail_view, .images_detail_view, .image_browse)[data-image-spacing="24"] {
  --image-gap: var(--ui-space-12);
}

/* Browse tiles (blocks/browse_tiles.css) take the same gap, and until the
   grid script has picked their columns, as many as fit. */
.image_browse {
  --block-browse-gap: var(--image-gap);
}

/* @end */

/* @group Lists */

/* The page's top gutter is cancelled (margins collapse, so a smaller margin
   would not show) and the gap becomes the list's own top padding. */
#main .content > :is(.images_icon_view, .images_thumbnail_view, .images_detail_view, .image_browse):first-child {
  margin-block-start: calc(-1 * var(--image-content-inset));
  padding-block-start: var(--image-gap);
}

:is(.images_icon_view, .images_thumbnail_view.grid, .images_detail_view, .image_browse[data-columns]) {
  display: grid;
  grid-template-columns: repeat(var(--image-columns), minmax(0, 1fr));
  gap: var(--image-gap);
}

/* The head script (libraries/storage/initial_layout_state) chooses the column
   count (data-columns) when parsing ends, before the first paint. While the
   page is parsed, the tiles stay out of sight in their place. Thus they do not
   show in one column and then jump into the grid (RULES §24.4). If the head
   script fails, they show after --ui-delay-enhancement. */
:root:not([data-layout-restored]) :is(.images_icon_view, .images_thumbnail_view.grid, .images_detail_view, .image_browse):not([data-columns]) > .item {
  visibility: hidden;
  animation: image-grid-reveal 0s linear var(--ui-delay-enhancement) forwards;
}

/* Until then, icons take as many columns as fit at their size, as browse
   tiles do. So the hidden tiles keep about the room that the grid gives them,
   not a row each as wide as the list. */
.images_icon_view:not([data-columns]) {
  grid-template-columns: repeat(auto-fill, minmax(min(var(--image-icon-size), 100%), 1fr));
}

@keyframes image-grid-reveal {
  to {
    visibility: visible;
  }
}

/* A masonry list stays hidden until masonry has laid it out and removed the
   class. The head script removes it from grids. */
.preload_hidden {
  visibility: hidden;
}

/* The gap is on the list before masonry adds its own classes, so the column
   count is chosen with it from the first layout. */
.images_thumbnail_view.masonry {
  --dpg-masonry-gap: var(--image-gap);

  gap: var(--image-gap);
}

@supports (display: grid-lanes) {
  .images_thumbnail_view.dpg-masonry-native {
    gap: var(--image-gap);
  }
}

.images_icon_view .item,
.images_icon_view .image_icon_select,
.images_icon_view .image_icon a,
.images_icon_view .image_icon .select input[type='checkbox'] {
  touch-action: pan-y;
}

/* Tiles are placed by the list; transforms only ever glide them (FLIP). */
:is(.images_icon_view, .images_thumbnail_view, .images_detail_view, .image_browse) > .item {
  min-width: 0;
  margin: 0;
  transform-origin: 0 0;
}

/* Off-screen grid tiles and cards skip their content's style and layout,
   including on every resize and new column count. Square tiles keep their
   size by aspect ratio, cards the height they last had. Masonry tiles are
   placed once and never laid out again, so they do not use it. A tile
   entering the viewport would lay out, and scrolling masonry runs no layout
   at all. */
:is(.images_icon_view, .images_thumbnail_view.grid, .images_detail_view, .image_browse) > .item {
  content-visibility: auto;
}

/* A card's height is its content's, so the first screenful of cards always
   lays out. WebKit first draws a skipped card at its placeholder height and
   then at its own, which moves every card below it (RULES §24.1). */
.images_detail_view > .item:nth-child(-n + 12) {
  content-visibility: visible;
}

/* @end */

/* @group Icons and grid thumbnails: square frames, the photo contained */

:is(.images_icon_view, .images_thumbnail_view.grid) > .item {
  display: block;
  /* The track's width, set explicitly: a tile skipped by content-visibility
     does not stretch, and would keep the width of an earlier layout. */
  width: 100%;
  aspect-ratio: 1;
}

:is(.images_icon_view, .images_thumbnail_view.grid) :is(.image_icon, .image_thumbnail) {
  display: block;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
}

:is(.images_icon_view, .images_thumbnail_view.grid) :is(.image_icon, .image_thumbnail) :is(.image_icon_select, .image_thumbnail_select, .image_icon_selected, .image_thumbnail_selected, .hidden, a) {
  display: block;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
}

:is(.images_icon_view, .images_thumbnail_view.grid) :is(.image_icon, .image_thumbnail) img {
  display: block;
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: none;
  padding: 0;
  object-fit: contain;
}

/* Icons keep DPG's mat around the photo. */
.images_icon_view > .item .image_icon img {
  padding: var(--ui-space-2);
}

/* @end */

/* @group Masonry and rows: the frame fills the column; the photo keeps its ratio */

:is(.images_thumbnail_view.masonry, .images_thumbnail_view.image_rows) .image_thumbnail {
  display: block;
  box-sizing: border-box;
  width: 100%;
  max-width: none;
}

:is(.images_thumbnail_view.masonry, .images_thumbnail_view.image_rows) .image_thumbnail img {
  display: block;
  width: 100%;
  max-width: none;
  height: auto;
}

/* @end */

/* @group Justified rows (?layout=rows): equal heights per row */

.images_thumbnail_view.image_rows {
  display: flex;
  flex-wrap: wrap;
  gap: var(--image-gap);
}

/* Keeps the last row at the chosen height instead of stretching it. */
.images_thumbnail_view.image_rows::after {
  flex: 1000000 1 0;
  content: '';
}

/* Width grows with the aspect ratio, so every tile in a row shares a height. */
.images_thumbnail_view.image_rows > .item {
  display: block;
  flex: var(--image-ratio) 1 calc(var(--image-ratio) * (var(--image-row-height) - var(--image-frame)) + var(--image-frame));
  aspect-ratio: auto;
  content-visibility: auto;
  contain-intrinsic-size: auto calc(var(--image-ratio) * var(--image-row-height)) auto var(--image-row-height);
}

/* @end */

/* @group Details: a card per image; the photo and its caption share one inset */

.images_detail_view > .item {
  width: 100%;
  container-type: inline-size;
  contain-intrinsic-block-size: auto 480px;
}

.images_detail_view .image_details {
  display: grid;
  align-content: start;
  align-items: start;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: repeat(7, auto);
  grid-template-areas:
    'image image'
    'title rating'
    'facts facts'
    'date date'
    'desc desc'
    'keywords keywords'
    'sets sets';
  column-gap: var(--ui-space-4);
  grid-auto-rows: 0;
  box-sizing: border-box;
  height: 100%;
  padding: var(--ui-space-4);
  overflow: hidden;
  color: var(--color-text);
  /* The detail markup ends with the rating as a bare character. It becomes an
     anonymous grid item in the first empty row, so it must take no height.
     Every child sets its own type. */
  font-size: 0;
  line-height: 0;
  background: var(--color-image-background);
  border: 1px solid var(--color-image-border);
  border-radius: var(--ui-radius-surface);
}

.images_detail_view .image_details:has(.image_detail.selected) {
  border-color: var(--color-link-strong);
  box-shadow: 0 0 0 1px var(--color-link-strong);
}

.images_detail_view .image_container {
  display: block;
  grid-area: image;
}

.images_detail_view .image_detail {
  display: block;
  border-width: 0;
}

.images_detail_view .image_detail_select {
  padding: 0;
}

.images_detail_view .image_detail img {
  display: block;
  width: 100%;
  max-width: none;
  height: auto;
}

/* Several columns: one image well shape so rows line up (a list may set
   its own, as the videos' 16:9 cards do). */
.images_detail_view:not([data-columns="1"]) .image_detail img {
  object-fit: contain;
  aspect-ratio: var(--image-well-ratio, 3 / 2);
}

.images_detail_view .detail_wrapper {
  display: contents;
}

.images_detail_view .image_details .line {
  display: block;
  min-width: 0;
  margin: 0;
  padding: 0;
  font-size: var(--ui-font-size-small);
  line-height: var(--ui-line-height-body);
  text-align: start;
}

.images_detail_view .image_details .line.title {
  grid-area: title;
  padding-block-start: var(--ui-space-4);
  overflow: hidden;
  font-family: var(--ui-font-family);
  font-size: var(--ui-font-size-control);
  font-weight: var(--ui-weight-medium);
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The rating, or a card's actions, ends the title's row. */
.images_detail_view .image_details :is(.line.rating, .line.actions) {
  align-self: end;
  grid-area: rating;
  padding-block-start: var(--ui-space-4);
}

.images_detail_view .image_details .line.rating {
  font-size: 0;
}

.images_detail_view .image_details .line.rating::after {
  color: var(--color-text-secondary);
  font-size: var(--ui-font-size-small);
}

.image_details .rating[data-rating='0']::after {
  content: '☆☆☆☆☆' var(--ui-icon-alt,);
}

.image_details .rating[data-rating='1']::after {
  content: '★☆☆☆☆' var(--ui-icon-alt,);
}

.image_details .rating[data-rating='2']::after {
  content: '★★☆☆☆' var(--ui-icon-alt,);
}

.image_details .rating[data-rating='3']::after {
  content: '★★★☆☆' var(--ui-icon-alt,);
}

.image_details .rating[data-rating='4']::after {
  content: '★★★★☆' var(--ui-icon-alt,);
}

.image_details .rating[data-rating='5']::after {
  content: '★★★★★' var(--ui-icon-alt,);
}

.images_detail_view .image_details .row {
  display: flex;
  flex-wrap: wrap;
  gap: 0 var(--ui-space-3);
  grid-area: facts;
  margin: 0;
  padding: var(--ui-space-1) 0 0;
  color: var(--color-text-secondary);
  font-size: var(--ui-font-size-small);
  line-height: var(--ui-line-height-body);
  font-variant-numeric: tabular-nums;
}

.images_detail_view .image_details .row .line {
  display: inline;
}

.images_detail_view .image_details .line.image_creation_date {
  grid-area: date;
  color: var(--color-text-secondary);
  font-variant-numeric: tabular-nums;
}

.images_detail_view .image_details .line.description {
  display: -webkit-box;
  grid-area: desc;
  padding-block-start: var(--ui-space-2);
  overflow: hidden;
  font-size: var(--ui-font-size-body);
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
}

.images_detail_view .image_details .line.description:empty {
  display: none;
}

.images_detail_view .image_details .line.keywords {
  grid-area: keywords;
  padding-block-start: var(--ui-space-2);
}

.images_detail_view .image_details .line.sets {
  grid-area: sets;
  padding-block-start: var(--ui-space-2);
}

.images_detail_view .image_details :is(.line.keywords, .line.sets):not(:has(div)) {
  display: none;
}

.images_detail_view .image_details :is(.line.keywords, .line.sets) > span {
  display: flex;
  flex-wrap: wrap;
  gap: var(--ui-space-1);
}

.images_detail_view .image_details :is(.line.keywords, .line.sets) span div {
  padding: var(--ui-space-1) var(--ui-space-2);
  overflow: hidden;
  font-size: var(--ui-font-size-small);
  line-height: var(--ui-line-height-body);
  text-overflow: ellipsis;
  white-space: nowrap;
  border-radius: var(--ui-radius-control);
}

.images_detail_view .image_details .line.keywords span div {
  padding-inline-start: var(--ui-space-6);
  color: var(--color-text-inverse);
  background: var(--color-neutral) var(--icon-keyword-chip) no-repeat var(--ui-space-2) center;
}

.images_detail_view .image_details .line.sets span div {
  max-width: 100%;
  color: var(--color-images-detail-set-text);
  background-color: var(--color-images-detail-set-bg);
}

.images_detail_view .image_details .line.sets span div::before {
  margin-inline-end: var(--ui-space-1);
  font-family: var(--ui-icon-font-family);
  font-size: var(--ui-font-size-body);
  font-weight: 900;
  content: '\f07c';
}

/* A wide card puts the photo beside its caption, one inset apart. */
@container (inline-size >= 560px) {
  .images_detail_view .image_details {
    grid-template-columns: minmax(0, 3fr) minmax(0, 2fr) auto;
    grid-template-rows: repeat(5, auto) 1fr;
    grid-template-areas:
      'image title rating'
      'image facts facts'
      'image date date'
      'image desc desc'
      'image keywords keywords'
      'image sets sets';
  }

  .images_detail_view .image_details :is(.line.title, .line.rating, .line.actions) {
    padding-block-start: 0;
  }
}

/* @end */

/* @group Image Frames */

/* Every image frame (icon, thumbnail, detail, full image) sits on the image
   well, with a loading spinner until its image loads, inside a hairline. */
:is(.image_icon, .image_thumbnail, .image_detail, .image) {
  position: relative;
  background: var(--block-image-grid-well);
  border: 1px solid var(--block-image-grid-border);
}

:is(.image_icon, .image_thumbnail, .image_detail, .image) > .dpg-spinner {
  position: absolute;
  inset: 0;
  margin: auto;
  width: var(--block-image-grid-spinner-size);
  height: var(--block-image-grid-spinner-size);
  color: var(--color-text-secondary);
  pointer-events: none;
}

:is(.image_icon, .image_thumbnail, .image_detail, .image).image-loaded > .dpg-spinner {
  display: none;
}

/* A hidden photograph shows faded, with the hidden glyph in its top corner
   (RULES §8.8: the fading only adds to the glyph). */
:is(.image_icon, .image_thumbnail, .image_detail, .image) .hidden img {
  opacity: var(--block-image-grid-hidden-opacity);
}

/* A tile's state marks (ApplicationHelper#image_tile_states) take no place in
   the frame. Their names are their aria-label. */
.image_state {
  position: absolute;
}

.image_state_hidden {
  inset-block-start: var(--ui-space-1);
  inset-inline-start: var(--ui-space-1);
  z-index: 1;
  display: grid;
  place-items: center;
  width: var(--block-image-grid-state-size);
  height: var(--block-image-grid-state-size);
  color: var(--color-media-overlay-text);
  background: var(--color-media-overlay-scrim);
  border-radius: var(--ui-radius-control);
  pointer-events: none;
}

.image_state_hidden::before {
  font: var(--ui-icon-weight) var(--ui-font-size-small)/1 var(--ui-icon-font-family);
  content: var(--ui-icon-eye-slash) var(--ui-icon-alt,);
}

/* The image link fills its frame, and an icon's frame clips its edge. So
   the link's focus ring is inside, as the selection box's is. */
:is(.image_icon, .image_thumbnail, .image_detail) a:focus-visible {
  outline: 2px solid var(--color-text);
  outline-offset: -2px;
}

:is(.image_icon, .image_thumbnail, .image_detail, .image) img {
  display: block;
}

.image_video {
  position: absolute;
  inset-block-start: 0;
  inset-inline-start: 0;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  background-image: url("/assets/images/image_video-67b48846.svg");
  background-position: center center;
  background-repeat: no-repeat;
  background-size: var(--block-image-grid-video-badge-size) var(--block-image-grid-video-badge-size);
  pointer-events: none;
}

/* A video image's duration chip (VideoTileHelper): the film glyph and how
   long the video runs. It sits in its frame's top-end corner, over the photo
   in the media overlay colours, and takes no clicks. A tile with a preview
   makes it its Play preview button (blocks/video_preview.css). It stays
   inside its frame. */
.image_video_chip {
  position: absolute;
  inset-block-start: var(--block-image-grid-video-chip-inset);
  inset-inline-end: var(--block-image-grid-video-chip-inset);
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: var(--ui-space-1);
  box-sizing: border-box;
  max-inline-size: calc(100% - var(--block-image-grid-video-chip-inset));
  margin: 0;
  padding: var(--ui-space-1) var(--ui-space-2);
  color: var(--color-media-overlay-text);
  font-family: var(--ui-font-family);
  font-size: var(--ui-font-size-small);
  font-weight: var(--ui-weight-medium);
  line-height: 1;
  white-space: nowrap;
  background-color: var(--color-media-overlay-scrim-strong);
  border: 0;
  border-radius: var(--ui-radius-control);
  pointer-events: none;
}

/* The glyph keeps one box, so the chip keeps its width when the glyph
   changes. */
.image_video_glyph {
  display: inline-grid;
  flex: none;
  place-items: center;
  inline-size: calc(var(--ui-font-size-small) * 1.25);
  block-size: var(--ui-font-size-small);
}

.image_video_glyph::before {
  font: var(--ui-icon-weight) var(--ui-font-size-small)/1 var(--ui-icon-font-family);
  content: var(--ui-icon-film) var(--ui-icon-alt,);
}

/* Tabular figures: each digit takes the same width in every chip. A length
   too long for its frame ("1 Std. 12 Min.") goes onto a second line at a
   space. */
.image_video_duration {
  font-variant-numeric: tabular-nums;
  text-align: end;
  white-space: normal;
}

/* In a filmstrip frame under 100px, the chip shows the length without its
   glyph. */
@container block-filmstrip-frame (inline-size < 100px) {
  .image_video_chip[role='img'] > .image_video_glyph {
    display: none;
  }
}

/* @end */

/* @group Image Icon */

.image_icon {
  display: block;
  box-sizing: border-box;
  width: 118px;
  height: 118px;
  overflow: hidden;
}

.image_icon img {
  box-sizing: border-box;
  width: 100%;
  max-width: 116px;
  height: 100%;
  max-height: 116px;
  padding: var(--ui-space-2);
}

/* @end */

/* @group Image Thumbnail, Detail and Image */

:is(.image_thumbnail, .image_detail, .image) {
  display: inline-block;
}

.image {
  margin-block-end: var(--ui-space-6);
}

.image img {
  max-width: 100%;
  height: auto;
}

/* @end */

/* @group Selection */

/* @group Frames: the selected state and the selection box */

.image_icon_selected {
  width: 100%;
  height: 100%;
}

.image_icon.selected,
.image_thumbnail.selected,
.image_detail.selected {
  border: 1px solid var(--block-image-grid-selected-border);
}

.image_icon_selected,
.image_icon.selected,
.image_thumbnail.selected,
.image_detail.selected {
  background-color: var(--color-neutral);
}

.image_icon_selected img,
.image_icon.selected img,
.image_thumbnail.selected img,
.image_detail.selected img {
  opacity: var(--block-image-grid-selected-opacity);
}

.image_icon_select {
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.image_thumbnail_select,
.image_detail_select,
.image_select {
  position: relative;
  display: block;
  padding: var(--ui-space-2);
  cursor: pointer;
}

.image_icon_select:hover,
.image_thumbnail_select:hover,
.image_detail_select:hover {
  background-image: var(--icon-image-select-hover);
  background-size: 8px;
}

.image_icon .select,
.image_thumbnail .select,
.image_detail .select {
  position: absolute;
  inset-inline-end: 0;
  inset-block-end: 0;
  display: grid;
  width: var(--ui-control-height);
  height: var(--ui-control-height);
  margin: 0;
  place-items: center;
  cursor: pointer;
}

/* The box sits inside the photograph's corner; its
   larger hit area extends beyond it. */
.image_thumbnail .select,
.image_detail .select {
  inset-inline-end: var(--ui-space-1);
  inset-block-end: var(--ui-space-1);
}

.image_icon .select input[type='checkbox'],
.image_thumbnail .select input[type='checkbox'],
.image_detail .select input[type='checkbox'] {
  position: static;
  box-sizing: border-box;
  width: 18px;
  height: 18px;
  margin: 0;
  padding: 0;
  background-color: var(--color-images-select-checkbox-bg);
  border: 2px solid var(--color-images-select-checkbox-border);
  cursor: pointer;
  /* Override global checkbox styling so we can draw this as an overlay control. */
  appearance: none;
}

.image_icon .select input[type='checkbox']:checked,
.image_thumbnail .select input[type='checkbox']:checked,
.image_detail .select input[type='checkbox']:checked {
  background-image: url("/assets/forms/check_mark_white-38599f55.svg");
  background-position: center;
  background-repeat: no-repeat;
  background-size: 10px;
}

/* On a touch screen the box itself is larger, for a finger. */
@media (pointer: coarse) {
  #main .images_icon_view input[type='checkbox'],
  #main .image_thumbnail input[type='checkbox'],
  #main .image_detail input[type='checkbox'] {
    width: var(--ui-space-8);
    height: var(--ui-space-8);
  }

  .image_icon .select input[type='checkbox']:checked,
  .image_thumbnail .select input[type='checkbox']:checked,
  .image_detail .select input[type='checkbox']:checked {
    background-size: calc(var(--ui-space-unit) * 5);
  }
}

.image_icon .select .text,
.image_thumbnail .select .text,
.image_detail .select .text,
.image .select .text {
  display: none;
}

/* @end */

/* @group Image */

.image .select {
  position: absolute;
  inset-inline-end: var(--ui-space-3);
  inset-block-end: var(--ui-space-3);
  width: 16px;
  height: 16px;
}

.image_select:hover {
  background-color: var(--color-surface-soft);
}

/* @end */

:is(.image_icon, .image_thumbnail, .image_detail) .select:has(input:focus-visible) {
  outline: 2px solid var(--color-text);
  outline-offset: -2px;
}

/* The toolbar's Select all box: sized with the toolbar's other controls and
   centred on the same line as its "0 selected" count. */
.image_selection {
  gap: var(--ui-space-1);
}

.image_selection_control {
  display: inline-grid;
  width: var(--ui-toolbar-control);
  height: var(--ui-toolbar-control);
  margin: 0;
  place-items: center;
  cursor: pointer;
}

/* The toolbar's generic label rule (inline-block, 48px) would undo the
   centring above. */
#options_bar .image_selection_control {
  display: inline-grid;
  min-width: 0;
}

.options_bar_item .image_selection_control input[type='checkbox'] {
  margin: 0;
}

:is(.image_icon, .image_thumbnail, .image_detail) .select:has(input:disabled) {
  opacity: 0.5;
  cursor: default;
}

/* @end */

/* @group Filmstrip (#scroll_navigation): review and upload */

/* The filmstrip's Show or hide button is a full-width bar under the strip.
   Its chevron points down while the strip shows and up while it is hidden.
   It turns with transform only. */
#toggle_scroll_navigation {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  box-sizing: content-box;
  inline-size: 100%;
  block-size: var(--ui-space-6);
  margin: 0;
  padding: 0 0 env(safe-area-inset-bottom);
  color: var(--color-text-secondary);
  background: var(--color-toolbar);
  border: 0;
  cursor: pointer;
}

#toggle_scroll_navigation::before {
  font: var(--ui-icon-weight) var(--ui-icon-size)/1 var(--ui-icon-font-family);
  transition: transform var(--ui-duration-feedback) var(--ui-ease-feedback);
  content: var(--ui-icon-angle-right) var(--ui-icon-alt,);
  transform: rotate(90deg);
}

#toggle_scroll_navigation[aria-expanded='false']::before {
  transform: rotate(-90deg);
}

#toggle_scroll_navigation:hover {
  color: var(--color-text);
}

#toggle_scroll_navigation:focus-visible {
  outline: 2px solid var(--color-text);
  outline-offset: -2px;
}

@media (pointer: coarse) {
  #toggle_scroll_navigation {
    block-size: var(--ui-space-8);
  }
}

@media (prefers-reduced-motion: reduce) {
  #toggle_scroll_navigation::before {
    transition: none;
  }
}

#scroll_navigation {
  flex: 0 0 auto;
  /* Reserve the resize handle before its interaction module arrives. */
  margin-block-start: var(--ui-space-3);
  overflow: scroll hidden;
  background-color: var(--color-toolbar);
}

#scroll_navigation.hidden {
  display: none;
}

/* The images near the open one carry a name between pages
   (--block-filmstrip-transition-name, set as the page is parsed by
   libraries/storage/initial_layout_state), so the strip slides along. */
@supports (view-transition-name: none) {
  #scroll_navigation li.item {
    view-transition-name: var(--block-filmstrip-transition-name, none);
  }
}

/* Reserve the strip while restoring its saved size and selected image. */
#scroll_navigation.panels-initializing > * {
  visibility: hidden;
  animation: image-grid-reveal 0s linear var(--ui-delay-enhancement) forwards;
}

/* A filmstrip frame is a size container, so its video chip fits a small
   frame (the chip's group above). */
#scroll_navigation .image_icon {
  inline-size: var(--block-filmstrip-thumbnail-size, var(--block-filmstrip-default-size, var(--ui-image-icon-size)));
  block-size: var(--block-filmstrip-thumbnail-size, var(--block-filmstrip-default-size, var(--ui-image-icon-size)));
  container: block-filmstrip-frame / inline-size;
}

#scroll_navigation .image_icon_select > a {
  display: grid;
  inline-size: 100%;
  block-size: 100%;
  place-items: center;
}

#scroll_navigation .image_icon img {
  max-inline-size: min(100%, calc(var(--block-filmstrip-image-width, 100px) + var(--ui-space-2) * 2));
  max-block-size: min(100%, calc(var(--block-filmstrip-image-height, 100px) + var(--ui-space-2) * 2));
  object-fit: contain;
}

.block_filmstrip_resize {
  position: relative;
  z-index: var(--ui-layer-overhang);
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  block-size: var(--ui-space-3);
  margin-block-end: calc(-1 * var(--ui-space-3));
  color: var(--color-control-border);
  background: var(--color-toolbar);
  cursor: ns-resize;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.block_filmstrip_resize::before {
  inline-size: var(--ui-space-8);
  block-size: var(--ui-space-1);
  background: currentColor;
  border-radius: var(--ui-radius-control);
  content: '';
}

.block_filmstrip_resize:is(:hover, :focus-visible, [data-dragging]) {
  color: var(--color-link-strong);
}

.block_filmstrip_resize:has(+ #scroll_navigation.hidden) {
  display: none;
}

@media (pointer: coarse) {
  #scroll_navigation {
    margin-block-start: var(--ui-touch-target);
  }

  .block_filmstrip_resize {
    block-size: var(--ui-touch-target);
    margin-block-end: calc(-1 * var(--ui-touch-target));
  }
}

.scroll_navigation {
  display: flex;
  width: max-content;
  padding: var(--block-image-grid-filmstrip-top) var(--ui-space-1) var(--ui-space-1);
}

.scroll_navigation li {
  flex: 0 0 auto;
  margin-inline: var(--block-image-grid-filmstrip-gap);
  overflow: hidden;
}

/* @end */

/* @group Custom order */

/* Tiles a person drags into order (images/libraries/sortable_facade): the
   dragged tile's ghost and its new position over the tile. */

.images_icon_view a,
.images_icon_view img,
.images_thumbnail_view a,
.images_thumbnail_view img,
.images_detail_view a,
.images_detail_view img,
.image_browse a {
  -webkit-user-drag: none;
  -webkit-user-select: none;
  user-select: none;
}


.images_icon_view li.sortable-ghost,
.images_thumbnail_view.grid li.sortable-ghost,
.images_thumbnail_view.masonry li.sortable-ghost,
.images_detail_view li.sortable-ghost,
.image_browse li.sortable-ghost {
  opacity: 0.2 !important;
}

.sortable-position-badge {
  position: absolute;
  inset: 0;
  z-index: var(--ui-layer-marker);
  width: max-content;
  min-width: var(--ui-control-height-inline);
  height: var(--ui-control-height-inline);
  margin: auto;
  padding: 0 var(--ui-space-2);
  color: var(--color-sortable-position-badge-text);
  font-size: var(--ui-font-size-small);
  font-weight: var(--ui-weight-strong);
  line-height: var(--ui-control-height-inline);
  text-align: center;
  background: var(--color-sortable-position-badge-bg);
  border-radius: calc(var(--ui-control-height-inline) / 2);
  pointer-events: none;
}

.gallery_dragging {
  z-index: var(--ui-layer-raised);
}

/* @end */

/* @group Drop to upload */

/* Drag-to-upload on a set's image list (images/list/drop_upload.js). The
   file_queue block draws each placeholder tile (preview, state, progress,
   Retry) and the whole-screen drop target. These rules fit the preview into
   the list's own tiles. */

/* A placeholder waits unseen until its preview is drawn, keeping its place
   so the grid lays out once. */
.drop_upload_placeholder[data-waiting] {
  visibility: hidden;
}

/* The preview sits inside the tile's mat (the icon image's padding, the
   thumbnail's own), so the file's band lines up with the image. */
.image_icon.drop_upload_surface,
.images_thumbnail_view .image_thumbnail.drop_upload_surface {
  --block-file-queue-inset: var(--ui-space-2);
}

/* Icon view: the preview fills the square tile inside the mat. */
.image_icon.drop_upload_surface .file_queue_image {
  box-sizing: border-box;
  height: 100%;
  padding: var(--ui-space-2);
  object-fit: contain;
}

/* Thumbnail view: the tile's width, and the preview's natural height. */
.images_thumbnail_view .image_thumbnail.drop_upload_surface {
  box-sizing: border-box;
  width: 100%;
  padding: var(--ui-space-2);
}

/* Thumbnail and detail tiles have no loading spinner behind the preview. */
:is(.images_thumbnail_view, .images_detail_view) .drop_upload_surface {
  background: none;
}

/* @end */

/* file_grid: the largest files in Images › Storage. Each file is a square
   admin icon in a reserved box. A video has its chip at the top. The size
   sits at the foot. The link's name holds both. */
.block_file_grid {
  --block-image-grid-video-chip-inset: var(--ui-space-1);

  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(calc(var(--ui-space-12) * 2), 1fr));
  gap: var(--ui-space-2);
  margin: 0;
  padding: 0;
  list-style: none;
}

.block_file_grid_item {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  background-color: var(--color-surface-muted);
}

.block_file_grid_item a,
.block_file_grid_item img {
  display: block;
  inline-size: 100%;
  block-size: 100%;
  object-fit: cover;
}

.block_file_grid_item a:focus-visible {
  outline: 2px solid var(--color-text);
  outline-offset: -2px;
}

.image_size_chip {
  position: absolute;
  inset-block-end: var(--ui-space-1);
  inset-inline-end: var(--ui-space-1);
  padding: var(--ui-space-1) var(--ui-space-2);
  color: var(--color-media-overlay-text);
  font-size: var(--ui-font-size-small);
  font-variant-numeric: tabular-nums;
  background: var(--color-media-overlay-scrim);
  border-radius: var(--ui-radius-control);
  pointer-events: none;
}
