/* ============================================================
   Tournoux Family — gallery.css
   Album index, photo grid, lightbox, and the admin gallery screens.
   Colours and sizes come from the :root variables in styles.css.
   ============================================================ */

/* --- Small shared bits ------------------------------------- */
.breadcrumb { margin-bottom: 1.5rem; font-size: 0.92rem; }
.muted-note { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1rem; }
.field-hint { color: var(--text-muted); font-size: 0.85rem; font-weight: 400; margin-top: 0.35rem; }
.count-note { color: var(--text-muted); font-weight: 400; font-size: 0.9rem; }
.admin-note { margin-top: 2rem; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* --- Album index ------------------------------------------- */
.album-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1.5rem;
}

.album-card {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  transition: box-shadow .18s ease, transform .18s ease;
}
.album-card:hover {
  box-shadow: 0 6px 20px rgba(0,0,0,.12);
  transform: translateY(-2px);
  color: inherit;
}

.album-card-image {
  aspect-ratio: 4 / 3;
  background: var(--bg-alt);
  overflow: hidden;
}
.album-card-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.album-card-body { padding: 1rem 1.15rem 1.25rem; }
.album-card-body h3 { color: var(--primary); font-size: 1.1rem; margin-bottom: 0.35rem; }
.album-card-body p {
  color: var(--text-muted);
  font-size: 0.92rem;
  margin-bottom: 0.5rem;
}
.album-card-count { color: var(--text-muted); font-size: 0.82rem; }

/* --- Public photo grid -------------------------------------- */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.85rem;
}

/* Tiles are buttons so the lightbox is keyboard-reachable. */
.photo-tile {
  position: relative;
  display: block;
  padding: 0;
  border: none;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-alt);
  cursor: pointer;
  aspect-ratio: 1 / 1;   /* fixed box means no layout shift as thumbs load */
  font: inherit;
}
.photo-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform .25s ease;
}
.photo-tile:hover img,
.photo-tile:focus-visible img { transform: scale(1.05); }
.photo-tile:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.photo-tile-caption {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 1.75rem 0.7rem 0.55rem;
  background: linear-gradient(to top, rgba(0,0,0,.72), transparent);
  color: #fff;
  font-size: 0.82rem;
  text-align: left;
  line-height: 1.35;
  pointer-events: none;
}

/* --- Lightbox ----------------------------------------------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(0,0,0,.94);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2.5rem 1rem 3.5rem;
}
.lightbox[hidden] { display: none; }

.lightbox-figure {
  max-width: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
}
.lightbox-figure img {
  max-width: 100%;
  max-height: calc(100vh - 8rem);
  object-fit: contain;
  border-radius: 2px;
}
.lightbox-figure figcaption {
  color: rgba(255,255,255,.85);
  font-size: 0.92rem;
  text-align: center;
  max-width: 60ch;
}

.lightbox-close,
.lightbox-nav {
  position: absolute;
  background: rgba(255,255,255,.1);
  color: #fff;
  border: none;
  cursor: pointer;
  line-height: 1;
  border-radius: 50%;
  transition: background .15s ease;
}
.lightbox-close:hover,
.lightbox-nav:hover { background: rgba(255,255,255,.25); }
.lightbox-close:focus-visible,
.lightbox-nav:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.lightbox-close {
  top: 1rem; right: 1rem;
  width: 2.75rem; height: 2.75rem;
  font-size: 1.9rem;
}
.lightbox-nav {
  top: 50%;
  transform: translateY(-50%);
  width: 3.25rem; height: 3.25rem;
  font-size: 2.4rem;
}
.lightbox-prev { left: 1rem; }
.lightbox-next { right: 1rem; }

.lightbox-counter {
  position: absolute;
  bottom: 1.1rem; left: 0; right: 0;
  text-align: center;
  color: rgba(255,255,255,.65);
  font-size: 0.85rem;
}

/* Stops the page behind the lightbox from scrolling. */
body.lightbox-open { overflow: hidden; }

/* --- Admin: upload dropzone ---------------------------------- */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  padding: 1.75rem 1.25rem;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--bg-alt);
  text-align: center;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
  margin-bottom: 1.25rem;
}
.dropzone:hover,
.dropzone.is-dragover { border-color: var(--accent); background: #fdf7ee; }
.dropzone input[type="file"] { margin: 0 auto; max-width: 100%; }
.dropzone-text { font-size: 1rem; }
.dropzone-hint {
  color: var(--text-muted);
  font-size: 0.85rem;
  max-width: 60ch;
  line-height: 1.5;
}
.dropzone-files {
  color: var(--primary);
  font-size: 0.88rem;
  font-weight: 600;
}

/* --- Admin: photo management grid ---------------------------- */
.admin-photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1.25rem;
  margin-bottom: 2rem;
}

.admin-photo {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}
.admin-photo > a { display: block; aspect-ratio: 4 / 3; background: var(--bg-alt); }
.admin-photo > a img { width: 100%; height: 100%; object-fit: cover; }

.admin-photo-form {
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1;
}
.admin-photo-form input[type="text"] {
  width: 100%;
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font: inherit;
  font-size: 0.88rem;
}
.admin-photo-form input[type="text"]:focus {
  outline: none;
  border-color: var(--primary);
}

.checkbox-line {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.checkbox-line input { margin: 0; }

.admin-photo-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.admin-photo-meta code {
  word-break: break-all;
  background: var(--bg-alt);
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
}

.admin-photo > form:last-child { padding: 0 0.75rem 0.75rem; }

/* Album thumbnail in the admin table */
.album-thumb {
  width: 72px;
  height: 54px;
  object-fit: cover;
  border-radius: 4px;
  background: var(--bg-alt);
}
.album-thumb--empty { display: block; border: 1px dashed var(--border); }

.inline-rename { display: flex; gap: 0.4rem; align-items: center; }
.inline-rename input[type="text"] {
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font: inherit;
  font-size: 0.85rem;
  min-width: 8rem;
}

/* --- Pagination ---------------------------------------------- */
.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin: 2rem 0 0.5rem;
}
.pager-status { color: var(--text-muted); font-size: 0.9rem; }

/* --- Reordering ---------------------------------------------- */
.drag-handle {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  line-height: 1;
  padding: 0.25rem 0.4rem;
  cursor: grab;
  border-radius: 4px;
  touch-action: none;    /* required, or a touch drag scrolls the page instead */
}
.drag-handle:hover { color: var(--primary); background: var(--bg-alt); }
.drag-handle:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.drag-handle:active { cursor: grabbing; }

/* pointer-events:none lets elementFromPoint find the tile underneath the one being dragged. */
.is-dragging {
  opacity: .55;
  pointer-events: none;
  outline: 2px dashed var(--accent);
  outline-offset: -2px;
}

.reorder-form { margin: 0.5rem 0 2rem; }
.reorder-form.is-dirty::before {
  content: "Order changed — not saved yet.";
  display: block;
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
}

.admin-photo-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-alt);
  min-height: 2.4rem;
}
.admin-photo-bar form { margin-left: auto; }
.admin-photo-bar .badge { margin-left: auto; }

/* --- Mobile -------------------------------------------------- */
@media (max-width: 720px) {
  .photo-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 0.5rem; }
  .album-grid { grid-template-columns: 1fr; }
  .admin-photo-grid { grid-template-columns: 1fr; }

  .lightbox { padding: 3.5rem 0.5rem; }
  .lightbox-nav { width: 2.75rem; height: 2.75rem; font-size: 2rem; }
  .lightbox-prev { left: 0.4rem; }
  .lightbox-next { right: 0.4rem; }
  .lightbox-figure img { max-height: calc(100vh - 9rem); }

  .inline-rename { flex-wrap: wrap; }
}
