/**
 * BGE Membership - Masonry Gallery CSS
 * 
 * Pinterest-style masonry layout for photo galleries
 *
 * @package    BGE_Membership
 * @subpackage Photos
 * 
 * FIXED: Added proper initial states and positioning for Masonry.js
 */

/* ==========================================================================
   Masonry Gallery Container
   ========================================================================== */

.bge-masonry-gallery {
	margin: 15px 0;
	padding: 0;
}

.bge-masonry-gallery__header {
	text-align: center;
	margin-bottom: 40px;
}

.bge-masonry-gallery__title {
	font-size: 32px;
	font-weight: 700;
	margin: 0 0 15px 0;
	color: #333;
}

.bge-masonry-gallery__description {
	font-size: 16px;
	color: #666;
	margin: 0;
	line-height: 1.6;
}

/* ==========================================================================
   Masonry Grid
   ========================================================================== */

.bge-masonry-grid {
	margin: 0 auto;
	max-width: 1400px;
	position: relative; /* CRITICAL: Allows Masonry to position items absolutely */
	/* Remove any grid properties - Masonry.js handles layout */
}

/* Grid sizer - defines column width for Masonry.js */
.bge-masonry-grid-sizer,
.bge-masonry-item {
	width: calc(25% - 15px); /* 4 columns with 20px gap */
}

.bge-masonry-gutter-sizer {
	width: 15px;
}

/* ==========================================================================
   Masonry Item (Photo Card)
   ========================================================================== */

.bge-masonry-item {
	margin-bottom: 20px;
	background: #fff;
	border-radius: 16px;
	overflow: hidden;
	box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
	transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
	cursor: pointer;
	/* CRITICAL: Initial opacity for fade-in effect */
	opacity: 0;
	/* CRITICAL: Let Masonry position the items */
	position: absolute;
}

/* After Masonry initializes, items will be faded in via JavaScript */
.bge-masonry-item.is-visible {
	opacity: 1;
}

.bge-masonry-item:hover {
	transform: translateY(-8px);
	box-shadow: 0 12px 32px rgba(0, 0, 0, 0.15);
}

/* Image Container */
.bge-masonry-item__image-wrapper {
	position: relative;
	width: 100%;
	overflow: hidden;
	background: #f5f5f5;
	display: block;
	/* No height constraint - let images use natural height for proper masonry layout */
}

.bge-masonry-item__image {
	width: 100%;
	height: auto;
	display: block;
	transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.bge-masonry-item:hover .bge-masonry-item__image {
	transform: scale(1.05);
}

/* Overlay */
.bge-masonry-item__overlay {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: linear-gradient(
		to bottom,
		rgba(0, 0, 0, 0) 0%,
		rgba(0, 0, 0, 0.4) 60%,
		rgba(0, 0, 0, 0.7) 100%
	);
	opacity: 0;
	transition: opacity 0.3s ease;
	display: flex;
	flex-direction: column;
	justify-content: flex-end;
	padding: 20px;
	color: #fff;
}

.bge-masonry-item:hover .bge-masonry-item__overlay {
	opacity: 1;
}

/* Quick View Button */
.bge-masonry-item__quick-view {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%) scale(0.8);
	background: rgba(255, 255, 255, 0.95);
	border: none;
	width: 60px;
	height: 60px;
	border-radius: 50%;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	opacity: 0;
	transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
	z-index: 10;
	box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.bge-masonry-item:hover .bge-masonry-item__quick-view {
	opacity: 1;
	transform: translate(-50%, -50%) scale(1);
}

.bge-masonry-item__quick-view:hover {
	background: #fff;
	transform: translate(-50%, -50%) scale(1.1);
}

.bge-masonry-item__quick-view .dashicons {
	font-size: 28px;
	width: 28px;
	height: 28px;
	color: #333;
}

/* Overlay Content */
.bge-masonry-item__overlay-title {
	font-size: 18px;
	font-weight: 600;
	margin: 0 0 8px 0;
	color: #fff;
	text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
	line-height: 1.3;
}

.bge-masonry-item__overlay-caption {
	font-size: 14px;
	color: rgba(255, 255, 255, 0.95);
	margin: 0;
	line-height: 1.5;
	text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* Item Info (Below Image) */
.bge-masonry-item__info {
	padding: 15px;
	background: #fff;
}

.bge-masonry-item__title {
	font-size: 16px;
	font-weight: 600;
	margin: 0 0 8px 0;
	color: #333;
	line-height: 1.4;
}

.bge-masonry-item__caption {
	font-size: 14px;
	color: #666;
	margin: 0;
	line-height: 1.6;
}

/* ==========================================================================
   Loading State
   ========================================================================== */

.bge-masonry-gallery__loading {
	text-align: center;
	padding: 80px 20px;
}

.bge-masonry-gallery__loading .dashicons {
	font-size: 64px;
	width: 64px;
	height: 64px;
	color: #4a90e2;
	animation: spin 1s linear infinite;
}

@keyframes spin {
	from { transform: rotate(0deg); }
	to { transform: rotate(360deg); }
}

.bge-masonry-gallery__loading-text {
	margin-top: 20px;
	font-size: 18px;
	color: #666;
}

/* ==========================================================================
   Empty State
   ========================================================================== */

.bge-masonry-gallery__empty {
	text-align: center;
	padding: 80px 20px;
	background: #f9f9f9;
	border: 2px dashed #ddd;
	border-radius: 16px;
}

.bge-masonry-gallery__empty .dashicons {
	font-size: 72px;
	width: 72px;
	height: 72px;
	color: #ccc;
	margin-bottom: 20px;
}

.bge-masonry-gallery__empty-title {
	font-size: 24px;
	color: #666;
	margin: 0 0 10px 0;
}

.bge-masonry-gallery__empty-text {
	font-size: 16px;
	color: #999;
	margin: 0;
}

/* ==========================================================================
   Lightbox
   ========================================================================== */

.bge-masonry-lightbox {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	z-index: 999999;
	display: flex;
	align-items: center;
	justify-content: center;
}

.bge-masonry-lightbox__overlay {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: rgba(0, 0, 0, 0.95);
	cursor: pointer;
}

.bge-masonry-lightbox__content {
	position: relative;
	max-width: 90vw;
	max-height: 90vh;
	display: flex;
	flex-direction: column;
	z-index: 1;
}

.bge-masonry-lightbox__image-container {
	display: flex;
	align-items: center;
	justify-content: center;
	flex: 1;
	margin-bottom: 20px;
}

.bge-masonry-lightbox__image-container img {
	max-width: 100%;
	max-height: 70vh;
	object-fit: contain;
	border-radius: 8px;
	box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

/* Lightbox Controls */
.bge-masonry-lightbox__close,
.bge-masonry-lightbox__prev,
.bge-masonry-lightbox__next {
	position: absolute;
	background: rgba(255, 255, 255, 0.9);
	border: none;
	width: 48px;
	height: 48px;
	border-radius: 50%;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: all 0.2s ease;
	z-index: 2;
}

.bge-masonry-lightbox__close:hover,
.bge-masonry-lightbox__prev:hover,
.bge-masonry-lightbox__next:hover {
	background: #fff;
	transform: scale(1.1);
}

.bge-masonry-lightbox__close {
	top: 20px;
	right: 20px;
	font-size: 32px;
	line-height: 1;
	color: #333;
}

.bge-masonry-lightbox__prev {
	top: 50%;
	left: 20px;
	transform: translateY(-50%);
}

.bge-masonry-lightbox__next {
	top: 50%;
	right: 20px;
	transform: translateY(-50%);
}

.bge-masonry-lightbox__prev:hover,
.bge-masonry-lightbox__next:hover {
	transform: translateY(-50%) scale(1.1);
}

.bge-masonry-lightbox__prev .dashicons,
.bge-masonry-lightbox__next .dashicons {
	font-size: 28px;
	width: 28px;
	height: 28px;
}

/* Lightbox Info */
.bge-masonry-lightbox__info {
	background: rgba(255, 255, 255, 0.95);
	padding: 20px;
	border-radius: 8px;
	max-width: 600px;
	margin: 0 auto;
}

.bge-masonry-lightbox__info h3 {
	margin: 0 0 10px 0;
	font-size: 20px;
	color: #333;
}

.bge-masonry-lightbox__info p {
	margin: 0;
	color: #666;
	line-height: 1.6;
}

/* ==========================================================================
   Responsive Design
   ========================================================================== */

/* Large Desktop */
@media (max-width: 1400px) {
	.bge-masonry-grid-sizer,
	.bge-masonry-item {
		width: calc(33.333% - 20px); /* 3 columns */
	}
}

/* Tablet */
@media (max-width: 1024px) {
	.bge-masonry-grid-sizer,
	.bge-masonry-item {
		width: calc(50% - 20px); /* 2 columns */
	}
	
	.bge-masonry-gallery__title {
		font-size: 28px;
	}
}

/* Mobile */
@media (max-width: 768px) {
	.bge-masonry-gutter-sizer {
		width: 15px;
	}
	
	.bge-masonry-grid-sizer,
	.bge-masonry-item {
		width: calc(50% - 15px); /* 2 columns, smaller gap */
		margin-bottom: 15px;
	}
	
	.bge-masonry-gallery__title {
		font-size: 24px;
	}
	
	.bge-masonry-item__info {
		padding: 12px;
	}
	
	.bge-masonry-item__title {
		font-size: 14px;
	}
	
	.bge-masonry-item__caption {
		font-size: 13px;
	}
	
	/* Lightbox adjustments */
	.bge-masonry-lightbox__content {
		max-width: 95vw;
		max-height: 95vh;
	}
	
	.bge-masonry-lightbox__image-container img {
		max-height: 60vh;
	}
	
	.bge-masonry-lightbox__close,
	.bge-masonry-lightbox__prev,
	.bge-masonry-lightbox__next {
		width: 40px;
		height: 40px;
	}
	
	.bge-masonry-lightbox__close {
		top: 10px;
		right: 10px;
	}
	
	.bge-masonry-lightbox__prev {
		left: 10px;
	}
	
	.bge-masonry-lightbox__next {
		right: 10px;
	}
}

/* Small Mobile */
@media (max-width: 480px) {
	.bge-masonry-grid-sizer,
	.bge-masonry-item {
		width: 100%; /* 1 column */
	}
	
	.bge-masonry-gallery__title {
		font-size: 20px;
	}
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
	.bge-masonry-item__overlay,
	.bge-masonry-item__quick-view,
	.bge-masonry-lightbox {
		display: none !important;
	}
	
	.bge-masonry-item {
		break-inside: avoid;
		page-break-inside: avoid;
		position: static !important; /* Override absolute positioning for print */
		opacity: 1 !important; /* Ensure all items visible */
	}
}

/* ==========================================================================
   Accessibility
   ========================================================================== */

.bge-masonry-item:focus-within {
	outline: 2px solid #4a90e2;
	outline-offset: 2px;
}

.bge-masonry-item__quick-view:focus {
	outline: 2px solid #4a90e2;
	outline-offset: 2px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
	.bge-masonry-item,
	.bge-masonry-item__image,
	.bge-masonry-item__overlay,
	.bge-masonry-item__quick-view {
		transition: none;
	}
	
	.bge-masonry-gallery__loading .dashicons {
		animation: none;
	}
}