/*
 * Image library (docs/vereinbarungen/bilder.md): list under /bilder, detail and edit pages. They
 * run in both shells like the news (layout "home" for the role `user`, backend layout for the
 * editorial team) and use the container `.home-content.wiki-page` and the search field
 * `.wiki-search` from wiki.css. Only what is specific to the library stands here.
 */

.images-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.images-heading__actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* Icon-only buttons and links of the head: at least 44 x 44 px for a thumb. */
.images-icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-l);
  color: var(--ink);
  background: var(--surface);
  cursor: pointer;
}

.images-icon-button--primary {
  border-color: var(--accent);
  color: var(--accent-ink);
  background: var(--accent);
}

.images-icon {
  display: block;
  width: 24px;
  height: 24px;
}

.images-offline {
  margin: 0 0 var(--space-4);
  color: var(--ink-muted);
}

/* The upload link and the search are greyed out while offline (online-only controller). */
.images-page [aria-disabled="true"],
.images-page :disabled {
  opacity: 0.5;
  pointer-events: none;
}

.images-filter {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0 0 var(--space-5);
}

.images-filter__link {
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-l);
  color: var(--ink);
  text-decoration: none;
  background: var(--surface);
}

/* The heart and the person icon: same look as the text links, but a square target. */
.images-filter__link--icon,
.images-filter__select {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
}

/* Starts the multiple selection, at the right end of the row. */
.images-filter__select {
  margin-left: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-l);
  color: var(--ink);
  background: var(--surface);
  cursor: pointer;
}

.images-filter__select[hidden] {
  display: none;
}

.images-filter__link[aria-current="page"] {
  border-color: var(--accent);
  color: var(--accent-strong);
  background: var(--accent-soft);
}

/* --- List: day groups with square tiles ------------------------------------------------------ */

.images-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: var(--space-3);
  margin: 0;
  padding: 0;
  list-style: none;
}

.images-grid > li {
  min-width: 0; /* grid item, see "Breite auf dem Handy" in wiki.css */
}

.images-tile {
  display: grid;
  gap: var(--space-1);
  color: var(--ink);
  text-decoration: none;
}

.images-tile__picture {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  border-radius: var(--radius-m);
  object-fit: cover;
  background: var(--accent-soft);
}

.images-tile__title {
  overflow: hidden;
  font-size: 0.9rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.images-older {
  margin-top: var(--space-5);
}

/* --- Detail and edit ------------------------------------------------------------------------- */

.images-large {
  display: block;
  margin: 0 0 var(--space-4);
}

.images-large__picture,
.images-edit-picture {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-m);
}

/* The square preview above a form. Its room is kept before it has arrived (the server scales a
   picture on the first request), so the form below does not move under a finger. */
.images-edit-picture {
  width: 160px;
  aspect-ratio: 1;
  margin: 0 0 var(--space-4);
  object-fit: cover;
  background: var(--accent-soft);
}

.images-facts {
  display: grid;
  gap: var(--space-1);
  margin: 0 0 var(--space-4);
  padding: 0;
  color: var(--ink-muted);
  font-size: 0.9rem;
  list-style: none;
}

.images-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.images-actions form {
  margin: 0;
}

.images-form {
  display: grid;
  gap: var(--space-4);
}

.images-form__field {
  display: grid;
  gap: var(--space-1);
}

.images-form__hint {
  margin: 0;
  color: var(--ink-muted);
  font-size: 0.9rem;
}

/* --- Uses and deletion requests --------------------------------------------------------------- */

.images-uses-section h3 {
  margin: 0 0 var(--space-2);
  font-size: 1rem;
}

.images-uses {
  display: grid;
  gap: var(--space-1);
  margin: 0 0 var(--space-4);
  padding: 0;
  list-style: none;
}

.images-uses__kind {
  margin-right: var(--space-2);
  color: var(--ink-muted);
  font-size: 0.85rem;
}

.images-request {
  margin: var(--space-3) 0 0;
}

.images-request__reason {
  display: block;
  color: var(--ink-muted);
}

.image-requests__image {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.image-requests__picture {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-s);
  object-fit: cover;
}

.image-requests__actions {
  display: grid;
  gap: var(--space-2);
}

.image-requests__actions form {
  margin: 0;
}

.image-requests__reject {
  display: grid;
  gap: var(--space-1);
}

/* --- Lightbox (image_lightbox_controller.js) -------------------------------------------------- */

.image-lightbox {
  width: 100vw;
  height: 100vh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: rgb(0 0 0 / 0.9);
}

.image-lightbox[open] {
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-lightbox::backdrop {
  background: rgb(0 0 0 / 0.9);
}

/* Safari before 15.4 has no <dialog>: lay it over the page while `open` is set. */
.image-lightbox--plain[open] {
  position: fixed;
  inset: 0;
  z-index: 100;
}

.image-lightbox__picture {
  width: 100%;
  height: 100%;
  object-fit: contain;
  cursor: zoom-out;
}

.image-lightbox__close {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  width: 2.75rem;
  height: 2.75rem;
  border: 0;
  border-radius: 50%;
  background: rgb(255 255 255 / 0.85);
  color: #000;
  font-size: 1.5rem;
  line-height: 1;
}

.image-lightbox__actions {
  position: absolute;
  bottom: var(--space-3);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  max-width: calc(100vw - 2 * var(--space-3));
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
}

.image-lightbox__albums {
  min-height: 44px;
  white-space: nowrap;
}

/* --- Full-screen view of an album (album_viewer_controller.js) -------------------------------- */

.album-viewer {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  overflow: hidden;
  background: #000;
}

.album-viewer::backdrop {
  background: #000;
}

/* Safari before 15.4 has no <dialog>: lay it over the page while `open` is set. */
.album-viewer--plain[open] {
  position: fixed;
  inset: 0;
  z-index: 100;
}

/* The swipe is the browser's own scroll: one slide per snap point. */
.album-viewer__track {
  display: flex;
  width: 100%;
  height: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior: contain;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  touch-action: pan-x;
}

.album-viewer__track::-webkit-scrollbar {
  display: none;
}

.album-viewer__track--zoomed {
  overflow-x: hidden;
  touch-action: none;
}

.album-viewer__slide {
  display: flex;
  flex: 0 0 100%;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  scroll-snap-align: center;
  scroll-snap-stop: always;
}

.album-viewer__picture {
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transform-origin: center;
}

.album-viewer__close,
.album-viewer__nav {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink);
  font-size: 1.75rem;
  line-height: 1;
}

.album-viewer__close {
  top: calc(var(--space-3) + env(safe-area-inset-top));
  right: calc(var(--space-3) + env(safe-area-inset-right));
}

.album-viewer__nav {
  bottom: calc(var(--space-3) + env(safe-area-inset-bottom));
}

.album-viewer__nav--previous {
  left: calc(var(--space-3) + env(safe-area-inset-left));
}

.album-viewer__nav--next {
  right: calc(var(--space-3) + env(safe-area-inset-right));
}

.album-viewer__nav:disabled {
  opacity: 0.4;
}

/* The overlay with the image's information: a dark panel at the bottom over the picture. The
   padding at the bottom keeps the arrows and the position (which sit above it) clear of the text. */
.album-viewer__info {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  max-height: 55vh;
  overflow-y: auto;
  padding: var(--space-4) calc(var(--space-4) + env(safe-area-inset-right))
    calc(var(--space-3) * 2 + 2.75rem + env(safe-area-inset-bottom)) calc(var(--space-4) + env(safe-area-inset-left));
  background: rgb(0 0 0 / 0.78);
  color: #fff;
  overscroll-behavior: contain;
  /* Sideways swipes are the view's (they change the image), upright ones scroll the panel. */
  touch-action: pan-y;
}

.album-viewer__info[hidden] {
  display: none;
}

.album-viewer__info a:not(.button) {
  color: inherit;
  text-decoration: underline;
}

.album-viewer__title {
  margin: 0 0 var(--space-2);
  color: inherit;
}

.album-viewer__info .images-description p {
  margin: 0 0 var(--space-2);
}

.album-viewer__info .images-facts {
  color: inherit;
  margin: 0 0 var(--space-3);
  padding-left: var(--space-4);
}

.album-viewer__actions {
  align-items: center;
}

.album-viewer__actions .button {
  min-height: 44px;
  background: #fff;
  color: #111;
}

.images-favourite--viewer .images-favourite__button {
  background: #fff;
  color: #111;
}

.images-favourite--viewer .images-favourite__button[aria-pressed="true"] {
  color: var(--brand-red);
}

.album-viewer__position {
  position: absolute;
  bottom: calc(var(--space-3) + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  min-height: 2.75rem;
  margin: 0;
  padding: 0 var(--space-4);
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  white-space: nowrap;
}

/* --- Albums on the favourites page and offline ------------------------------------------------- */

.albums-stored,
.albums-offline-note,
.albums-offline-switch__hint {
  margin: 0 0 var(--space-3);
  color: var(--ink-muted);
  font-size: 0.9rem;
}

.albums-offline-switch {
  display: grid;
  gap: var(--space-2);
  margin: 0 0 var(--space-4);
}

.albums-offline-switch__form {
  margin: 0;
}

.albums-offline-switch__button {
  min-height: 44px;
}

.albums-offline-switch__button[aria-checked="true"] {
  border-color: var(--accent-strong);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.albums-offline-switch__button::after {
  content: "";
  display: inline-block;
  width: 0.7rem;
  height: 0.7rem;
  margin-left: var(--space-2);
  border: 2px solid currentColor;
  border-radius: 50%;
}

.albums-offline-switch__button[aria-checked="true"]::after {
  background: currentColor;
}

.images-album__badge {
  justify-self: start;
  padding: 0 var(--space-2);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.8rem;
  font-weight: 600;
}

.images-album__hint {
  color: var(--ink-muted);
  font-size: 0.85rem;
}

/* A heart set offline whose picture the cached page does not hold yet. */
.images-grid__item--pending .images-tile {
  outline: 2px dashed var(--line);
  outline-offset: -2px;
}

/* --- Hearts, albums and the multiple selection (docs/vereinbarungen/alben.md) ------------------ */

.images-heart {
  display: block;
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.images-favourite {
  margin: 0;
}

.images-favourite__button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--ink);
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  cursor: pointer;
}

.images-favourite__button[aria-pressed="true"] {
  color: var(--brand-red);
}

.images-favourite__button[aria-pressed="true"] .images-heart {
  fill: var(--brand-red);
  stroke: var(--brand-red);
}

.images-grid__item {
  position: relative;
}

.images-album-actions {
  align-items: center;
  margin: 0 0 var(--space-4);
}

.images-in-albums {
  margin: 0 0 var(--space-4);
}

.images-selection-start {
  margin: 0 0 var(--space-4);
}

/* Selection mode: a picked picture gets an outline. */
.images-tile__check {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  width: 24px;
  height: 24px;
  margin: 0;
  border: 2px solid var(--ink);
  border-radius: var(--radius-s);
  background: var(--surface);
  appearance: none;
  cursor: pointer;
}

/* 44 px hit area around the 24 px box. */
.images-tile__check::before {
  content: "";
  position: absolute;
  inset: -10px;
}

.images-tile__check:checked {
  border-color: var(--accent);
  background: var(--accent);
}

.images-tile__check:checked::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 7px;
  width: 6px;
  height: 12px;
  border: solid var(--accent-ink);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.images-page .button[hidden],
.images-tile__check[hidden] {
  display: none;
}

.images-grid__item--picked .images-tile__picture {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}

.images-selection-bar {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2) var(--space-3);
  margin-top: var(--space-4);
  padding: var(--space-3) var(--space-3) calc(var(--space-3) + env(safe-area-inset-bottom));
  border-radius: var(--radius-l) var(--radius-l) 0 0;
  background: var(--surface-raised);
  box-shadow: var(--shadow-2);
}

.images-selection-bar[hidden] {
  display: none;
}

.images-selection-bar__count {
  margin: 0;
  font-weight: 600;
}

.images-selection-bar__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.images-selection-bar__actions form {
  margin: 0;
}

/* Albums: cards like the tiles. */
.images-album {
  display: grid;
  gap: var(--space-1);
  color: var(--ink);
  text-decoration: none;
}

.images-album__placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  aspect-ratio: 1;
  border-radius: var(--radius-m);
  color: var(--accent-strong);
  background: var(--accent-soft);
}

.images-album__name {
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.images-album__count {
  color: var(--ink-muted);
  font-size: 0.9rem;
  font-weight: 400;
}

.images-grid + .images-form {
  margin-top: var(--space-5);
}

/* Assign page and the image's albums page. */
.images-strip {
  display: flex;
  gap: var(--space-2);
  margin: 0 0 var(--space-4);
  padding: 0;
  overflow-x: auto;
  list-style: none;
}

.images-strip__picture {
  display: block;
  width: 64px;
  height: 64px;
  border-radius: var(--radius-s);
  object-fit: cover;
}

.images-assign-albums {
  display: grid;
  gap: var(--space-2);
  margin: 0 0 var(--space-5);
  padding: 0;
  list-style: none;
}

.images-assign-albums form {
  margin: 0;
}

.images-assign-albums .button {
  width: 100%;
  justify-content: flex-start;
  min-height: 44px;
}

.images-assign-count {
  margin: 0 0 var(--space-3);
}

.images-album-check {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 44px;
}

.images-form__error {
  margin: 0;
  color: var(--danger);
  font-size: 0.9rem;
}
