/* Grid Layout Styles */
.photos-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 40px;
    width: 100%;
    max-width: 1600px;
    margin: 20px auto;
    padding: 20px;
    box-sizing: border-box;
    min-height: 200px;
    position: relative;
}

/* Ensure proper document flow */
.photo-div {
    width: 100%;
    min-height: 100vh;
    position: relative;
    margin-bottom: 40px;
    overflow: visible;
}

/* Ensure infinite scroll content is properly contained */
.infinite-scroll-container {
    width: 100%;
    position: relative;
    overflow: visible;
}

/* Status elements should not affect layout flow */
.page-load-status {
    width: 100%;
    margin: 20px 0;
    padding: 20px 0;
    text-align: center;
}

.infinite-scroll-request,
.infinite-scroll-last,
.infinite-scroll-error {
    width: 100%;
    margin: 0;
    padding: 20px 0;
    min-height: 60px;
}

/* Photo item styles — photography carries the system's one shadow */
.photo {
    width: 100%;
    margin: 0;
    padding: 0;
    position: relative;
    overflow: hidden;
    border-radius: var(--radius-sm, 8px);
    box-shadow: var(--shadow-photo, 3px 5px 30px rgba(0, 0, 0, 0.16));
    background-color: var(--surface-black, #111113);
    min-height: 200px;
}

.photo a {
    display: block;
    width: 100%;
    height: 0;
    padding-bottom: 100%; /* 1:1 aspect ratio */
    position: relative;
    overflow: hidden;
    border-radius: 8px;
    background-color: var(--surface-black, #111113); /* developer tray, not a light card */
}

.photo img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    border-radius: 8px;
}

/* Hover feedback — image scales, no lift (Flat Hover Rule) */
.photo:hover img {
    transform: scale(1.04);
}

/* Loading state: darkroom develop. While the image loads (its renditions may
   still be warming in the background) the card sits under a pulsing red
   safelight, the arriving image showing as a dim red-washed blur; on load
   (js/photo-develop.js adds .loaded) it develops into the sharp print. */
.photo:not(.loaded) img {
    opacity: 0.15;
    filter: blur(14px) saturate(0.5) brightness(0.85);
}

.photo a::before {
    content: '';
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(ellipse at 50% 38%,
        rgba(218, 41, 28, 0.35) 0%,
        rgba(218, 41, 28, 0.1) 55%,
        transparent 100%);
    animation: safelightPulse 2.4s infinite ease-in-out;
    z-index: 1;
    opacity: 1;
    transition: opacity 0.9s ease;
    pointer-events: none;
}

.photo.loaded a::before {
    opacity: 0;
    animation: none;
}

.photo.loaded img {
    opacity: 1;
    filter: none;
    transition: opacity 0.9s ease, filter 0.9s ease, transform 0.3s ease;
}

/* Image was already in the browser cache — show it, don't re-develop. */
.photo.loaded-instant img {
    transition: transform 0.3s ease;
}

.photo.loaded-instant a::before {
    transition: none;
}

@media (prefers-reduced-motion: reduce) {
    .photo a::before { animation: none; }
    .photo:not(.loaded) img { opacity: 0.4; filter: none; }
    .photo.loaded img { transition: transform 0.3s ease; }
}

/* Animations */
@keyframes safelightPulse {
    0%, 100% { opacity: 0.65; }
    50% { opacity: 1; }
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Staggered animation delays */
.photo:nth-child(3n+1) { animation-delay: 0.05s; }
.photo:nth-child(3n+2) { animation-delay: 0.1s; }
.photo:nth-child(3n+3) { animation-delay: 0.15s; }

/* Responsive grid */
@media (min-width: 1601px) {
    .photos-container {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (max-width: 1200px) {
    .photos-container {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 992px) {
    .photos-container {
        grid-template-columns: repeat(2, 1fr);
        gap: 30px;
    }
}

@media (max-width: 576px) {
    .photos-container {
        grid-template-columns: 1fr;
        gap: 30px;
        padding: 15px;
    }
}

/* Override Bootstrap container for photo grid */
.photo-grid-container {
    width: 100% !important;
    max-width: 1600px !important;
    margin: 0 auto !important;
    padding: 0 !important;
}

/* Ensure grid layout takes precedence */
.photos-container {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 20px !important;
    padding: 20px !important;
    width: 100% !important;
}

@media (max-width: 992px) {
    .photos-container {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
}

@media (max-width: 576px) {
    .photos-container {
        grid-template-columns: minmax(0, 1fr) !important;
    }
}