/* ===== Masonry (grid layout) ===== */
.masonry {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
  align-items: stretch;
  grid-auto-flow: row dense;
}
@media (max-width: 575.98px){
  .masonry {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }
}

.masonry-item {
  position: relative;
  background: var(--fx-surface); /* серый фон для читаемых границ */
  border-radius: .75rem;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0,0,0,.06);
  transition: transform .08s ease-in-out, box-shadow .12s ease-in-out;
  padding-bottom: 100%; /* квадрат */
}
.masonry-item:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px rgba(0,0,0,.10);
}
.masonry-item img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
  z-index: 1;
}
.masonry-item::after{
  content:'';
  position:absolute;
  inset:0;
  border-radius:inherit;
  pointer-events:none;
  border:0 solid transparent;
  z-index:3;
  transition:border-color .15s ease, border-width .15s ease, border-style .15s ease;
}
.masonry-item.tile-on-current::after{
  border-width:3px;
  border-color:var(--bs-primary);
  border-style:solid;
}
.masonry-item.tile-on-other::after{
  border-width:3px;
  border-color:var(--line);
  border-style:solid;
}

/* Оверлеи действий */
.photo-actions {
  position: absolute;
  inset: .5rem .5rem auto auto;
  display: flex;
  gap: .5rem;
  z-index: 5;
}
.photo-actions .btn {
  width: 36px; height: 36px;
  border-radius: 999px;
  padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
  touch-action: manipulation; /* Отключаем 300ms задержку iOS Safari */
}
.photo-zoom {
  position: absolute;
  right: .5rem; bottom: .5rem;
  z-index: 5;
}
.photo-zoom .btn {
  width: 36px; height: 36px; border-radius: 999px; padding: 0;
  /* center icon inside the circular button */
  display: inline-flex; align-items: center; justify-content: center; line-height: 1;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
  touch-action: manipulation; /* Отключаем 300ms задержку iOS Safari */
}

/* Плашка "Главное" */
.badge-main {
  position: absolute;
  left: .5rem; top: .5rem;
  z-index: 5;
}

/* ===== Галерея-модалка (список) ===== */
.gallery-modal .modal-body {
  background: var(--fx-bg);
}
.gallery-modal .nav-tabs .nav-link {
  border: 0; border-bottom: 2px solid transparent;
  color: var(--bs-secondary);
}
.gallery-modal .nav-tabs .nav-link.active {
  color: var(--bs-body-color);
  border-bottom-color: var(--bs-primary);
  background: transparent;
}

/* ===== Просмотрщик ===== */
@media (max-width: 575.98px) {
  #photoViewer .modal-dialog { margin: 0; }
  #photoViewer .modal-content { border: 0; border-radius: 0; }
  #photoViewer .modal-dialog { width: 100vw; height: 100vh; }
  #photoViewer .modal-body { padding: 0; }
}
zoom-stage {
  position: relative;
  width: 100%;
  height: 70vh;
  background: var(--bs-body-bg);
  overflow: hidden;
  touch-action: none;
}
@media (max-width: 575.98px) { .zoom-stage { height: calc(100vh - 112px); } }
.zoom-img {
  will-change: transform;
  transform-origin: 0 0;
  user-select: none; -webkit-user-drag: none;
  max-width: none;
}
.floating-ui, .zoom-controls, .nav-arrows { z-index: 20; }
.floating-ui { position:absolute; right:1rem; bottom:1rem; display:flex; flex-direction:column; gap:.5rem; }
.zoom-controls { position:absolute; left:1rem; bottom:1rem; display:flex; flex-direction:column; gap:.5rem; }
.nav-arrows { position:absolute; inset:0; display:flex; align-items:center; justify-content:space-between; padding:0 .5rem; pointer-events:none; }
.nav-arrows .btn { pointer-events:auto; width:44px; height:44px; border-radius:50%; display:inline-flex; align-items:center; justify-content:center; opacity:.9; box-shadow:0 4px 16px rgba(0,0,0,.25); }
.status-badges { display:flex; align-items:center; gap:.5rem; }
