/* FBR Gallery Frontend Styles */

/* --- Body Scroll Prevention --- */
body.fbr-lightbox-open {
	overflow: hidden;
}

/* --- Keyframes --- */
@keyframes fbr-spin {
	0% { transform: rotate(0deg); }
	100% { transform: rotate(360deg); }
}

/* --- Gallery Layout Base --- */
.fbr-gallery {
	display: grid; /* Default to grid for most styles */
	gap: 10px;
	width: 100%;
}

.fbr-gallery-item {
	position: relative;
	line-height: 0;
	aspect-ratio: 1 / 1; /* Default aspect ratio for cropped thumbnails */
    opacity: 0; /* Initially hidden, will fade in with JS */
    transition: opacity 0.3s ease; /* Smooth fade-in */
}

.fbr-gallery-item img {
	display: block;
	width: 90%;
	height: 90%;
	object-fit: cover; /* Default for cropped thumbnails */
	cursor: pointer;
	border-radius: 8px;
	transition: border-radius 0.3s ease, opacity 0.3s ease, transform 0.3s ease;
}

@media (hover: hover) and (pointer: fine) {
	.fbr-gallery-item img:hover {
		opacity: 0.8;
		transform: scale(1.15);
		border: 1px solid white;
		box-sizing: border-box;
		border-radius: 0;
		filter: drop-shadow(0 0 0.15rem black);
	}
}

.fbr-gallery-item.is-hidden {
	display: none !important;
}

/* --- Gallery Style: Default (Current behavior) --- */
/* Uses flexible columns based on content width. No inline style for grid-template-columns */
/* Images are cropped to square by default */
.fbr-gallery-style-default {
    /* --fbr-min-col-width is a custom property for responsive grid columns */
    --fbr-min-col-width: 150px; /* Minimum width for each column */
    grid-template-columns: repeat(auto-fit, minmax(var(--fbr-min-col-width), 1fr));
}

/* --- Gallery Style: Grid --- */
/* Uses fixed number of columns. grid-template-columns is set via inline style based on shortcode attribute */
.fbr-gallery-style-grid {
    /* grid-template-columns is set inline by shortcode.php */
}

/* Specific styling for grid-cropped vs grid-uncropped */
.fbr-gallery-style-grid.fbr-gallery-cropped .fbr-gallery-item {
    aspect-ratio: 1 / 1; /* Enforce square ratio for items */
}
.fbr-gallery-style-grid.fbr-gallery-cropped .fbr-gallery-item img {
    object-fit: cover; /* Crop to fill square container */
}

.fbr-gallery-style-grid:not(.fbr-gallery-cropped) .fbr-gallery-item {
    /* No fixed aspect ratio here, image will determine height */
    aspect-ratio: unset;
}
.fbr-gallery-style-grid:not(.fbr-gallery-cropped) .fbr-gallery-item img {
    object-fit: contain; /* Contain within item, show full image */
    height: auto; /* Allow height to adjust to aspect ratio */
    width: 100%; /* Ensure width fills column */
}


/* --- Gallery Style: Masonry --- */
/* Masonry.js handles positioning, so we need to prepare the container and items */
.fbr-gallery-style-masonry {
    display: block; /* Masonry.js works with block-level containers */
    position: relative; /* Essential for absolutely positioned items */
    /* Gaps will be handled by Masonry.js options, but a fallback margin can be useful */
    margin: 0 auto; /* Center the masonry layout */
}

.fbr-gallery-style-masonry .fbr-gallery-item {
    width: calc((100% / var(--fbr-columns, 3)) - 10px); /* Adjust width based on columns, consider gap */
    margin-bottom: 10px; /* Gap between rows for masonry */
    aspect-ratio: unset; /* Masonry should maintain image aspect ratio */
    /* Masonry.js will set position: absolute and top/left values */
}

.fbr-gallery-style-masonry .fbr-gallery-item img {
    object-fit: contain; /* Ensure image is fully visible */
    height: auto; /* Allow natural height based on aspect ratio */
    width: 100%; /* Fill column width */
}

/* Fallback for Masonry on very small screens (1 column) */
@media (max-width: 480px) {
    .fbr-gallery-style-masonry .fbr-gallery-item {
        width: 100%;
    }
}


/* --- Filter Navigation --- */
.fbr-filter-nav {
	margin-bottom: 20px;
	text-align: center;
}

.fbr-filter-nav button {
	background-color: #eee;
	border: 1px solid #ccc;
	padding: 8px 15px;
	margin: 0 5px 5px 0;
	cursor: pointer;
	border-radius: 20px;
	font-size: 14px;
	line-height: 1.2;
	color: #333;
	transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

@media (hover: hover) and (pointer: fine) {
	.fbr-filter-nav button:hover {
		background-color: #ddd;
	}
}

.fbr-filter-nav button.active {
	background-color: #0073aa;
	color: white;
	border-color: #0073aa;
	cursor: default;
}

.fbr-filter-nav button.active:hover {
	background-color: #0073aa;
}

/* --- Gallery Thumbnail Loader --- */
.fbr-gallery-loading {
	min-height: 150px;
	position: relative;
}

.fbr-gallery-loading::after {
    content: '';
    display: block;
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    margin-top: -20px;
    margin-left: -20px;
    border: 4px solid rgba(0, 0, 0, 0.1);
    border-top-color: #3498db;
    border-radius: 50%;
    animation: fbr-spin 1s linear infinite;
}

/* --- Lightbox --- */
#fbr-lightbox-overlay {
	position: fixed;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	background-color: rgba(10, 10, 10, 0.9);
	z-index: 99999;
	transition: opacity 0.25s ease;
    box-sizing: border-box;

    /* New Flexbox Layout for Lightbox Overlay */
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center; /* Center items horizontally */
    padding: 20px;
}

/* Lightbox Content Area (holds the image) */
#fbr-lightbox-content {
	position: relative;
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    margin: 10px 0; /* Add some vertical margin between info boxes and image */
    max-width: 100%; /* Ensure it doesn't overflow padding */
    max-height: 100%; /* Ensure it doesn't overflow padding */
}

/* Image inside Lightbox */
#fbr-lightbox-image {
	display: block;
	max-width: 100%;
	max-height: 100%; /* Ensure image respects container height */
	object-fit: contain;
	border-radius: 4px;
	box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
	transition: opacity 0.25s ease, transform 0.25s ease;
	opacity: 0;
	transform: scale(0.95);
}

#fbr-lightbox-image.is-visible {
	opacity: 1;
	transform: scale(1);
}

/* Control Buttons (Close, Prev, Next) */
#fbr-lightbox-close,
#fbr-prev-image,
#fbr-next-image {
	position: absolute; /* Position relative to #fbr-lightbox-overlay */
	background-color: rgba(30, 30, 30, 0.6);
	color: #fff;
	border: 1px solid rgba(255, 255, 255, 0.2);
	cursor: pointer;
	z-index: 100002;
	opacity: 0.7;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: translateZ(0); /* Add a baseline transform to prevent jump */
	transition: all 0.2s ease;
	-webkit-backdrop-filter: blur(8px);
	backdrop-filter: blur(8px);
	border-radius: 50%;
	width: 44px;
	height: 44px;
}

#fbr-lightbox-close:focus-visible,
#fbr-prev-image:focus-visible,
#fbr-next-image:focus-visible {
	outline: 2px solid #3498db;
	outline-offset: 2px;
	opacity: 1;
}

@media (hover: hover) and (pointer: fine) {
	#fbr-lightbox-close:hover { /* Only close button here as it's separate */
		opacity: 1;
		transform: scale(1.1) translateZ(0);
	}
    #fbr-prev-image:hover,
    #fbr-next-image:hover { /* Fixed: Apply combined transform directly */
        opacity: 1;
        transform: translateY(-50%) scale(1.1) translateZ(0);
    }
}

#fbr-lightbox-close { top: 20px; right: 20px; font-size: 2em; }
#fbr-prev-image { top: 50%; left: 20px; transform: translateY(-50%) translateZ(0); font-size: 1.5em; }
#fbr-next-image { top: 50%; right: 20px; transform: translateY(-50%) translateZ(0); font-size: 1.5em; }


/* Lightbox Data Containers (Info & Counter) */
#fbr-lightbox-details, .fbr-lightbox-data-container {
	/* Removed position: fixed; and related positioning properties */
	z-index: 100001;
	background: rgba(30, 30, 30, 0.6);
	color: #fff;
	padding: 8px 15px;
	border-radius: 6px;
    font-size: 0.85em; /* Smaller font for general info */
    text-align: center; /* Center horizontally */
	-webkit-backdrop-filter: blur(8px);
	backdrop-filter: blur(8px);
    box-sizing: border-box;
    max-width: 90%; /* Constrain width to prevent being too wide */
}

/* Number and filter tag (at the top) */
.fbr-lightbox-data-container {
    align-self: center; /* Center horizontally in flex column */
    margin-bottom: 10px; /* Space from image */
    order: -1; /* Place at the very top in flex column */
}
/* Image information (at the bottom) */
#fbr-lightbox-details {
    align-self: center; /* Center horizontally in flex column */
    margin-top: 10px; /* Space from image */
    order: 1; /* Place at the very bottom in flex column */
}


/* Responsive adjustments for smaller screens */
@media (max-width: 768px) {
    #fbr-lightbox-overlay {
        padding: 10px;
    }
    #fbr-lightbox-close { top: 10px; right: 10px; }
    #fbr-prev-image { left: 10px; }
    #fbr-next-image { right: 10px; }

    .fbr-lightbox-data-container, #fbr-lightbox-details {
        max-width: 95%; /* Adjust max-width for tighter space */
        font-size: 0.8em; /* Even smaller text */
        padding: 6px 10px;
    }
    #fbr-lightbox-details #fbr-lightbox-title { font-size: 0.9em; }
    #fbr-lightbox-details #fbr-lightbox-caption { font-size: 0.75em; }
    #fbr-lightbox-details #fbr-lightbox-description { font-size: 0.75em; }
}


#fbr-lightbox-title { font-size: 1.1em; font-weight: bold; }
#fbr-lightbox-caption { font-size: 0.9em; opacity: 0.8; }
#fbr-lightbox-loader {
	display: flex;
	align-items: center;
	justify-content: center;
	position: absolute;
	z-index: 10;
	padding: 10px 20px;
	background-color: rgba(20, 20, 20, 0.5);
    color: #fff;
	border-radius: 5px;
}
#fbr-lightbox-loader .spinner-icon {
	width: 30px;
	height: 30px;
	margin-right: 12px;
	border: 3px solid rgba(255, 255, 255, 0.2);
	border-top-color: #fff;
	border-radius: 50%;
	animation: fbr-spin 1s linear infinite;
}

/* Tooltip */
#fbr-image-tooltip {
    position: absolute;
    display: none;
    background-color: rgba(0, 0, 0, 0.75);
    color: #fff;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 16px;
    line-height: 1.4;
    z-index: 100001;
    pointer-events: none;
    white-space: nowrap;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Disable text selection in lightbox */
#fbr-lightbox-details, #fbr-lightbox-filter-tag, #fbr-lightbox-counter {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}