/*
 * Upload page of the image library (docs/vereinbarungen/bilder.md) and the greyed state of the
 * `online-only` controller, which the start page uses too.
 */

.online-only--off {
  opacity: 0.5;
  pointer-events: none;
}

.image-upload {
  --image-upload-tile: 112px;
}

.image-upload__pick {
  display: flex;
  width: 100%;
  min-height: 4rem;
  font-size: 1.1rem;
  cursor: pointer;
}

/* The real input stays in the page for the picker but is replaced by the big button. */
.image-upload__input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  opacity: 0;
}

.image-upload__pick:has(:focus-visible) {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.image-upload__pick:has(:disabled) {
  opacity: 0.5;
  cursor: not-allowed;
}

.image-upload__tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--image-upload-tile), 1fr));
  gap: var(--space-3);
  margin: var(--space-4) 0;
  padding: 0;
  list-style: none;
}

.image-upload__tiles:empty {
  display: none;
}

.image-upload__tile {
  position: relative;
  display: grid;
  min-width: 0;
  gap: var(--space-1);
}

.image-upload__frame {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  overflow: hidden;
  border: 2px solid var(--line);
  border-radius: var(--radius-m);
  color: var(--ink-muted);
  background: var(--accent-soft);
}

.image-upload__preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-upload__icon {
  width: 40%;
  height: 40%;
}

.image-upload__progress {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 6px;
  background: color-mix(in srgb, var(--ink) 20%, transparent);
}

.image-upload__bar {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 0.15s linear;
}

.image-upload__check {
  position: absolute;
  top: var(--space-1);
  right: var(--space-1);
  display: none;
  width: 1.6rem;
  height: 1.6rem;
  padding: 0.3rem;
  border-radius: 50%;
  color: var(--accent-ink);
  background: var(--ok);
}

.image-upload__message {
  margin: 0;
  color: var(--danger);
  font-size: 0.85rem;
  overflow-wrap: anywhere;
}

.image-upload__message:empty {
  display: none;
}

.image-upload__tile[data-state="done"] .image-upload__progress,
.image-upload__tile[data-state="failed"] .image-upload__progress {
  display: none;
}

.image-upload__tile[data-state="done"] .image-upload__check {
  display: block;
}

.image-upload__tile[data-state="done"] .image-upload__frame {
  border-color: var(--ok);
}

.image-upload__tile[data-state="failed"] .image-upload__frame {
  border-color: var(--danger);
}

.image-upload__tile[data-retry="true"] {
  cursor: pointer;
}

.image-upload__description {
  margin: var(--space-4) 0;
}

.image-upload__label {
  margin: 0 0 var(--space-2);
  font-weight: 600;
}

.image-upload__done {
  display: flex;
  width: 100%;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

.image-upload__done:disabled {
  opacity: 0.6;
}

/* The picker dialog of the wiki and news editors (images/_picker). */
.image-picker {
  width: min(40rem, calc(100vw - 2 * var(--space-4)));
  max-height: calc(100vh - 2 * var(--space-4));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-l);
  color: var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow-2, 0 12px 32px rgba(0, 0, 0, 0.18));
}

.image-picker::backdrop {
  background: rgba(0, 0, 0, 0.35);
}

/* Safari before 15.4 has no <dialog>: lay it over the page while `open` is set. */
.image-picker--plain[open] {
  position: fixed;
  inset: var(--space-4);
  margin: auto;
  overflow: auto;
  z-index: 100;
}

.image-picker__body {
  display: grid;
  gap: var(--space-4);
  padding: var(--space-5);
}

.image-picker__body h2 {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 680;
}

.image-picker__search {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* The source (all images, favourites, an album) takes its own row above the search. */
.image-picker__source {
  flex: 1 1 100%;
}

.image-picker__search input {
  flex: 1;
  min-width: 0;
}

.image-picker__upload {
  margin-top: var(--space-3);
}

.image-picker__upload-button {
  cursor: pointer;
}

.image-picker__file {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
}

.image-picker__upload-button:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.image-picker__error {
  margin: var(--space-3) 0 0;
  color: var(--danger);
}

.image-picker__busy {
  display: flex;
  margin-top: var(--space-3);
}

.image-picker__busy[hidden] {
  display: none;
}

.image-picker__results {
  max-height: 50vh;
  margin-top: var(--space-3);
  overflow-y: auto;
}

.image-picker__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(7rem, 1fr));
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
}

.image-picker__tile {
  display: grid;
  gap: var(--space-1);
  width: 100%;
  padding: var(--space-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  color: inherit;
  background: var(--surface-raised);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.image-picker__tile:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.image-picker__picture {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--radius-s);
}

.image-picker__title {
  overflow: hidden;
  font-size: 0.85rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-picker__empty {
  margin: 0;
  color: var(--ink-muted);
}

.image-picker__preview {
  display: block;
  max-width: 100%;
  max-height: 14rem;
  margin: 0 auto var(--space-3);
  border-radius: var(--radius-s);
}

.image-picker__open {
  /* Grid fields (wiki editor) and flex fields (news form, `.templates-page .field`). */
  justify-self: start;
  align-self: flex-start;
}
