/* Photos: thumbnails, the gallery, and adding them one at a time, previewed
   (photos/_upload_field). */

@layer components {
  .thumb-col { width: 4.5rem; }
  .thumb {
    width: 3.5rem;
    height: 3.5rem;
    object-fit: cover;
    border-radius: 10px;
    display: block;
  }

  .gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.5rem;

    img {
      width: 100%;
      height: auto;
      border-radius: var(--radius-box);
      display: block;
    }
  }

  /* Saved photos and new picks in one grid, in order; the first (the cover)
     takes four cells. */
  .photo-picks {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-auto-flow: dense;
    gap: 0.6rem;
    margin-bottom: 0.75rem;

    &:empty { display: none; }
    /* the grid holds the pointer while dragging */
    &.dragging { cursor: move; }
  }

  /* The four-arrows "move" cursor says it can be dragged; the buttons keep the
     normal pointer. */
  .photo-pick {
    position: relative;
    margin: 0;
    cursor: move;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    border-radius: 12px;

    &:first-child { grid-column: span 2; grid-row: span 2; }
    img {
      width: 100%;
      height: 100%;
      aspect-ratio: 1;
      object-fit: cover;
      border-radius: 12px;
      border: 2px solid var(--ink);
      display: block;
      -webkit-user-drag: none;
    }

    /* While dragging: a see-through copy of the photo under the pointer, and
       a slot where it lands (.photo-slot, striped in the business colors, like
       the lists' "Suelta aquí"). */
    &.photo-ghost {
      position: fixed;
      top: 0;
      left: 0;
      z-index: 50;
      opacity: 0.7;
      pointer-events: none;
      box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25);

      .cover-tag { display: none; }
    }

    figcaption {
      position: absolute;
      left: 0.35rem;
      right: 0.35rem;
      bottom: 0.35rem;
      display: flex;
      justify-content: space-between;
      align-items: center;
      gap: 0.3rem;

      .new-tag { background: var(--paper); }
    }
    button {
      margin-left: auto;
      padding: 0.1rem 0.55rem;
      font-size: 0.8rem;
    }
    .cover-tag {
      display: none;
      position: absolute;
      top: 0.45rem;
      left: 0.45rem;
      background: var(--ink);
      color: var(--paper);
      font-size: 0.8rem;
      font-weight: 700;
      padding: 0.1rem 0.6rem;
      border-radius: var(--radius-pill);
    }
    &:first-child .cover-tag { display: inline-block; }
  }

  .photo-slot {
    cursor: move;

    .drop-slot-box {
      aspect-ratio: 1;
      height: 100%;
      padding: 0.4rem;
      text-align: center;
    }
    &:not(:first-child) .drop-slot-box span {
      font-size: 0.62rem;
      letter-spacing: 0.06em;
      padding: 0.1rem 0.45rem;
      border-width: 1.5px;
    }
  }

  /* "Add a photo": a label styled as a button, over a hidden file input. */
  .field label.button {
    display: inline-flex;
    margin-bottom: 0;

    &[hidden] { display: none; }
  }
  label.button:focus-within {
    outline: 3px solid var(--ink);
    outline-offset: 2px;
  }
  .photo-error { color: var(--alert); font-weight: 700; margin: 0.5rem 0 0; }
  .photo-picker .field-hint { margin-top: 0.5rem; }
}
