/* Fotos (/photos, /de/fotos): Unternavigation, Kacheln, Galerie im Zeilenlayout, Lightbox, Schlagwörter,
   Weltkarte und Statistik. Übernommen von den früheren Fotoseiten, auf die Tokens dieser Seite umgestellt.
   Nur auf den Fotoseiten geladen ({% block styles %}); die Schicht „pages“ legt app/styles.py an.
   Galerie und Lightbox steuert js/photos/gallery.js; unter 45rem (720 px) stehen die Fotos untereinander. */

@layer pages {
  .photos {
    --photos-overlay: rgb(0 0 0 / 0.92);
    --photos-control: rgb(0 0 0 / 0.4);
    --photos-control-hover: rgb(0 0 0 / 0.7);
    --photos-pill: rgb(0 0 0 / 0.55);
    --photos-pill-hover: rgb(0 0 0 / 0.8);
    --photos-marker: #e8587a;
  }

  .photos__lead {
    margin: 0 0 var(--space-lg);
    max-width: var(--width-prose);
    color: var(--color-text-muted);
  }

  .photos__rss {
    margin: var(--space-xl) 0 0;
    font-size: var(--text-sm);
  }

  /* Unternavigation: der aktive Punkt ist die h1 der Seite */
  .photos-subnav {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: var(--space-xs) var(--space-lg);
    margin: 0 0 var(--space-lg);
  }

  .photos-subnav__title {
    display: contents;
    margin: 0;
    font: inherit;
  }

  .photos-subnav__link {
    color: var(--color-text-muted);
    font-size: var(--text-xl);
    font-weight: 500;
    line-height: var(--leading-tight);
    letter-spacing: -0.01em;
    text-decoration: none;

    &:hover {
      color: var(--color-accent-strong);
    }

    &.is-active {
      color: var(--color-text);
      font-weight: 700;
    }
  }

  /* Kopf eines Albums: Brotkrumen, Titel, Beschreibung */
  .photos-head {
    max-width: 60rem;
    margin-bottom: var(--space-lg);
  }

  .photos-head__title {
    margin: 0;
    font-size: var(--text-2xl);
    letter-spacing: -0.02em;
  }

  .photos-head__lead,
  .photos-head__meta {
    margin: var(--space-xs) 0 0;
    color: var(--color-text-muted);
  }

  .photos-head__hash {
    margin-right: 0.05em;
    color: var(--color-accent);
    font-family: var(--font-mono);
    opacity: 0.75;
  }

  .photos-breadcrumbs ol {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2xs) var(--space-xs);
    margin: 0 0 var(--space-md);
    padding: 0;
    list-style: none;
    color: var(--color-text-muted);
    font-size: var(--text-sm);

    & li + li::before {
      content: "/";
      margin-right: var(--space-xs);
      color: var(--color-text-faint);
    }

    & a {
      color: var(--color-text-muted);
      text-decoration: none;

      &:hover {
        color: var(--color-accent-strong);
      }
    }

    & [aria-current="page"] {
      color: var(--color-text);
      font-weight: 700;
    }
  }

  .photos-breadcrumbs__home {
    display: inline-flex;
    align-items: center;
    vertical-align: -0.2em;

    & .icon {
      width: 1.25rem;
      height: 1.25rem;
    }
  }

  .photos-back {
    margin: 0 0 var(--space-sm);
    font-size: var(--text-sm);

    & a {
      display: inline-flex;
      align-items: center;
      gap: var(--space-xs);
      color: var(--color-text-muted);
      text-decoration: none;

      &:hover,
      &:focus-visible {
        color: var(--color-accent-strong);
      }
    }
  }

  .photos-back--bottom {
    margin: var(--space-xl) 0 0;
  }

  /* Kacheln für Kollektionen und Sets (.photo-cards, .photo-card) stehen in components/lists/photo-cards.css, die Startseite nutzt sie auch. */

  /* Galerie im Zeilenlayout: gallery.js setzt Position und Größe jedes Fotos */
  .justified {
    position: relative;
    width: 100%;
    min-height: 100px;
  }

  .photo-item {
    position: absolute;
    margin: 0;
    opacity: 0;
    transition: opacity 0.2s ease;

    &[data-laid-out="true"] {
      opacity: 1;
    }

    /* Ohne JavaScript: Fotos untereinander */
    :root:not(.js) & {
      position: static;
      opacity: 1;
      margin-bottom: var(--space-sm);
    }
  }

  .photo-btn {
    display: block;
    width: 100%;
    height: 100%;
    padding: 0;
    overflow: hidden;
    background: var(--color-surface);
    border: 0;
    border-radius: 6px;
    cursor: zoom-in;

    & img {
      display: block;
      width: 100%;
      height: 100%;
      object-fit: cover;
      transition: transform 0.3s ease;
    }

    &:hover img,
    &:focus-visible img {
      transform: scale(1.04);
    }

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

    &:disabled {
      cursor: default;
    }
  }

  /* Set und Datum über dem Foto (Schlagwortseiten), sichtbar beim Darüberfahren */
  .photo-meta {
    position: absolute;
    right: var(--space-xs);
    bottom: var(--space-xs);
    left: var(--space-xs);
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin: 0;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;

    .photo-item:hover &,
    .photo-item:focus-within & {
      opacity: 1;
    }
  }

  .photo-meta__pill {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    max-width: 100%;
    padding: 0.25rem 0.55rem;
    background: var(--photos-pill);
    color: rgb(255 255 255 / 0.95);
    border-radius: 999px;
    font-size: var(--text-xs);
    line-height: 1.2;
    text-decoration: none;
    pointer-events: auto;
    transition: background var(--duration-fast) ease;

    & span,
    & time {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    & .icon {
      flex: none;
      width: 0.875rem;
      height: 0.875rem;
    }
  }

  a.photo-meta__pill:hover,
  a.photo-meta__pill:focus-visible {
    background: var(--photos-pill-hover);
    color: #fff;
  }

  @media (max-width: 45rem) {
    .justified {
      display: flex;
      flex-direction: column;
      gap: var(--space-lg);
      height: auto !important;
    }

    .photo-item {
      position: static;
      width: 100%;
      opacity: 1;
    }

    .photo-btn img {
      height: auto;
    }

    .photo-btn:hover img,
    .photo-btn:focus-visible img {
      transform: none;
    }

    .photo-meta {
      position: static;
      margin-top: var(--space-xs);
      opacity: 1;
    }

    .photo-meta__pill {
      padding: 0;
      background: transparent;
      color: var(--color-text-muted);
      font-size: var(--text-sm);
    }

    a.photo-meta__pill:hover,
    a.photo-meta__pill:focus-visible {
      background: transparent;
      color: var(--color-accent-strong);
    }

    .lightbox {
      display: none;
    }
  }

  /* Lightbox */
  .lightbox {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100dvh;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background: transparent;
    border: 0;
    color: #fff;

    &::backdrop {
      background: rgb(0 0 0 / 0.92);
    }
  }

  .lightbox__figure {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-md);
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 4rem;
  }

  .lightbox__img {
    flex: 1;
    min-height: 0;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: var(--radius-sm);
    touch-action: pan-y;
    cursor: grab;
    user-select: none;
    -webkit-user-drag: none;

    &:active {
      cursor: grabbing;
    }

    &.is-sliding {
      transition: transform 220ms ease;
    }
  }

  .lightbox__caption {
    max-width: 60ch;
    color: rgb(255 255 255 / 0.85);
    text-align: center;
  }

  .lightbox__button {
    position: absolute;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 3rem;
    height: 3rem;
    padding: 0;
    background: rgb(0 0 0 / 0.4);
    color: #fff;
    border: 0;
    border-radius: 50%;
    font-size: 1.75rem;
    line-height: 1;
    cursor: pointer;
    transition: background var(--duration-fast) ease;

    &:hover:not(:disabled) {
      background: rgb(0 0 0 / 0.7);
    }

    &:disabled {
      opacity: 0.2;
      cursor: not-allowed;
    }

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

  .lightbox__close {
    top: var(--space-md);
    right: var(--space-md);
  }

  .lightbox__prev,
  .lightbox__next {
    top: 50%;
    transform: translateY(-50%);
  }

  .lightbox__prev {
    left: var(--space-md);
  }

  .lightbox__next {
    right: var(--space-md);
  }

  .lightbox__set {
    position: absolute;
    top: var(--space-md);
    left: var(--space-md);
    z-index: 1;
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    padding: 0.5rem 0.9rem;
    background: rgb(0 0 0 / 0.4);
    color: #fff;
    border-radius: 999px;
    font-size: var(--text-sm);
    line-height: 1;
    text-decoration: none;
    transition: background var(--duration-fast) ease;

    &:hover,
    &:focus-visible {
      background: rgb(0 0 0 / 0.7);
      color: #fff;
    }

    &[hidden] {
      display: none;
    }

    & .icon {
      width: 1.25rem;
      height: 1.25rem;
    }
  }

  .lightbox__counter {
    position: absolute;
    bottom: var(--space-md);
    left: 50%;
    margin: 0;
    color: rgb(255 255 255 / 0.7);
    font-size: var(--text-xs);
    transform: translateX(-50%);
  }

  /* Schlagwörter */
  .tag-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .tag-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.45rem 0.85rem 0.45rem 0.7rem;
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border-strong);
    border-radius: 999px;
    font-size: var(--text-sm);
    text-decoration: none;
    transition:
      border-color var(--duration-fast) ease,
      color var(--duration-fast) ease,
      transform var(--duration-fast) ease;

    &:hover,
    &:focus-visible {
      border-color: var(--color-accent);
      color: var(--color-accent-strong);
      transform: translateY(-1px);
    }
  }

  .tag-chip__hash {
    color: var(--color-accent);
    font-family: var(--font-mono);
    font-weight: 700;
    opacity: 0.75;

    .tag-chip:hover & {
      opacity: 1;
    }
  }

  .tag-chip__name {
    font-weight: 500;
  }

  .tag-chip__count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.4rem;
    height: 1.4rem;
    padding: 0 0.4rem;
    background: var(--color-surface-raised);
    color: var(--color-text-muted);
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    transition:
      background-color var(--duration-fast) ease,
      color var(--duration-fast) ease;

    .tag-chip:hover & {
      background: var(--color-accent);
      color: var(--color-on-accent);
    }
  }

  /* Weltkarte */
  .photo-map {
    height: calc(100dvh - 220px);
    min-height: 420px;
    overflow: hidden;
    background: var(--color-surface);
    border-radius: var(--radius-md);
  }

  .photo-map__note {
    margin: 0;
    padding: var(--space-lg);
    color: var(--color-text-muted);
  }

  .photo-map {
    /* leaflet.css liegt in keiner Schicht und gewinnt sonst immer; !important in einer Schicht schlägt es. */
    & .leaflet-popup-content-wrapper {
      padding: 0 !important;
      background: #fff !important;
      border-radius: 4px !important;
      box-shadow: 0 4px 16px rgb(0 0 0 / 0.15) !important;
    }

    & .leaflet-popup-content {
      width: auto !important;
      margin: 0 !important;
    }

    & .leaflet-popup-tip {
      background: #fff !important;
    }

    & .leaflet-popup-close-button {
      top: 6px !important;
      right: 8px !important;
    }

    & .leaflet-control-attribution {
      padding: 1px 4px !important;
      background: rgb(255 255 255 / 0.8) !important;
      font-size: 0.6rem !important;
    }
  }

  .cluster-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: var(--photos-marker);
    color: #fff;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgb(232 88 122 / 0.4);
    font-size: 0.8rem;
    font-weight: 600;
  }

  .map-popup {
    width: 220px;
  }

  .map-popup__link {
    display: block;
    color: #17181b;
    text-decoration: none;

    &:hover .map-popup__title {
      color: #a9500f;
    }
  }

  .map-popup__img {
    display: block;
    width: 100%;
    height: 148px;
    object-fit: cover;
    border-radius: 4px 4px 0 0;
  }

  .map-popup__title {
    margin: 0;
    padding: 0.5rem 0.6rem 0.6rem;
    font-size: 0.78rem;
    line-height: 1.4;
  }

  .map-popup__set {
    display: block;
    color: #55575d;
  }

  /* Statistik */
  .photo-stats {
    padding-top: var(--space-xs);
  }

  .photo-stats__total {
    margin: 0 0 var(--space-xl);
    color: var(--color-text-muted);
    font-size: var(--text-sm);
  }

  .photo-stats__grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem 3rem;

    @media (max-width: 40rem) {
      grid-template-columns: 1fr;
    }
  }

  /* Kamera und Objektiv über die volle Breite: Chart.js gibt der Beschriftungsachse höchstens die halbe Breite,
     lange Objektivnamen würden in einer halben Spalte abgeschnitten. */
  .photo-stats__grid--top {
    grid-template-columns: 1fr;
    margin-bottom: 2rem;
  }

  .photo-stats__chart {
    position: relative;
    overflow: hidden;
    padding: clamp(1rem, 2vw, 1.25rem);
    background: linear-gradient(135deg, var(--color-surface), var(--color-surface-raised));
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
  }

  .photo-stats__title {
    margin: 0 0 var(--space-sm);
    color: var(--color-text-muted);
    font-size: var(--text-xs);
    font-weight: 600;
    letter-spacing: 0.07em;
    text-transform: uppercase;
  }

  .photo-stats__canvas {
    position: relative;
    height: 220px;
  }

  .photo-stats__canvas--tall {
    height: 140px;
  }
}
