/*
 * Tatoli Tiled Gallery – CSS
 */

/* ───── Gallery Grid ───── */
.ttg-gallery {
	display: grid;
	gap: 4px;
	margin: 1rem 0 1.5rem;
	width: 100%;
	grid-auto-rows: 220px;
}

/* Column variants — auto-fit for flexible columns */
.ttg-columns-1 { grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }
.ttg-columns-2 { grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }
.ttg-columns-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.ttg-columns-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.ttg-columns-5 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.ttg-columns-6 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.ttg-columns-7 { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
.ttg-columns-8 { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
.ttg-columns-9 { grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); }

/* ───── Gallery Item ───── */
.ttg-item {
	margin: 0;
	padding: 0;
	position: relative;
	overflow: hidden;
	border-radius: 3px;
	background: #f8f9fa;
	height: 100%;
}

.ttg-item img {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	object-fit: cover;
	transition: transform 0.3s ease, filter 0.3s ease;
	cursor: pointer;
}

.ttg-item-link {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	z-index: 1;
	line-height: 0;
}

/* Hover effect */
.ttg-item:hover img {
	transform: scale(1.05);
	filter: brightness(0.85);
}

/* Overlay icon on hover */
.ttg-item-link::after {
	content: '';
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: rgba(0, 0, 0, 0) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' fill='white' viewBox='0 0 16 16'%3E%3Cpath d='M6.002 5.5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0z'/%3E%3Cpath d='M2.002 1a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V3a2 2 0 0 0-2-2h-12zm12 1a1 1 0 0 1 1 1v6.5l-3.777-1.947a.5.5 0 0 0-.577.093l-3.71 3.71-2.66-1.772a.5.5 0 0 0-.63.062L1.002 12V3a1 1 0 0 1 1-1h12z'/%3E%3C/svg%3E") center center no-repeat;
	background-size: 28px 28px;
	opacity: 0;
	transition: opacity 0.3s ease, background-color 0.3s ease;
	pointer-events: none;
	border-radius: 3px;
}

.ttg-item-link:hover::after {
	opacity: 1;
	background-color: rgba(0, 0, 0, 0.25);
}

/* ───── Captions ───── */
.ttg-caption {
	position: absolute;
	bottom: 0;
	left: 0;
	right: 0;
	padding: 6px 8px;
	margin: 0;
	font-size: 0.7rem;
	line-height: 1.3;
	color: #fff;
	background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
	opacity: 0;
	transition: opacity 0.3s ease;
	pointer-events: none;
}

.ttg-item:hover .ttg-caption {
	opacity: 1;
}

/* ───── Responsive ───── */
@media (max-width: 767px) {
	.ttg-columns-4,
	.ttg-columns-5,
	.ttg-columns-6,
	.ttg-columns-7,
	.ttg-columns-8,
	.ttg-columns-9 {
		grid-template-columns: repeat(3, 1fr);
	}
	.ttg-columns-3 {
		grid-template-columns: repeat(2, 1fr);
	}
	.ttg-gallery {
		gap: 3px;
	}
}

@media (max-width: 480px) {
	.ttg-columns-3,
	.ttg-columns-4,
	.ttg-columns-5,
	.ttg-columns-6,
	.ttg-columns-7,
	.ttg-columns-8,
	.ttg-columns-9 {
		grid-template-columns: repeat(2, 1fr);
	}
	.ttg-gallery {
		gap: 2px;
	}
	.ttg-item-link::after {
		display: none; /* no hover on mobile */
	}
}

/* ───── Type: Tiled Mosaic ───── */
.ttg-type-tiled-mosaic {
	grid-template-columns: repeat(3, 1fr);
	grid-auto-rows: 180px;
	gap: 4px;
}

.ttg-type-tiled-mosaic .ttg-item:nth-child(5n+1) {
	grid-column: span 2;
	grid-row: span 2;
}

.ttg-type-tiled-mosaic .ttg-item:nth-child(5n+4) {
	grid-column: span 2;
}

@media (max-width: 767px) {
	.ttg-type-tiled-mosaic {
		grid-template-columns: repeat(2, 1fr);
		grid-auto-rows: 140px;
	}
	.ttg-type-tiled-mosaic .ttg-item:nth-child(5n+1) {
		grid-column: span 2;
		grid-row: span 1;
	}
	.ttg-type-tiled-mosaic .ttg-item:nth-child(5n+4) {
		grid-column: span 1;
	}
}

/* ───── Type: Square Tiles ───── */
.ttg-type-square-tiles .ttg-item {
	aspect-ratio: 1 / 1;
}

.ttg-type-square-tiles .ttg-item img {
	aspect-ratio: 1 / 1;
	object-fit: cover;
}

/* ───── Type: Circles ───── */
.ttg-type-circles {
	gap: 12px;
}

.ttg-type-circles .ttg-item {
	border-radius: 50%;
	aspect-ratio: 1 / 1;
	overflow: hidden;
}

.ttg-type-circles .ttg-item img {
	aspect-ratio: 1 / 1;
	object-fit: cover;
	border-radius: 50%;
	transition: transform 0.4s ease;
}

.ttg-type-circles .ttg-item:hover img {
	transform: scale(1.1);
}

.ttg-type-circles .ttg-item-link::after {
	border-radius: 50%;
}

.ttg-type-circles .ttg-caption {
	border-radius: 0 0 50% 50%;
	text-align: center;
	padding: 0 8px 20%;
	font-size: 0.65rem;
}

@media (max-width: 767px) {
	.ttg-type-circles {
		gap: 8px;
	}
}

/* ───── Dark Mode ───── */
@media (prefers-color-scheme: dark) {
	.ttg-item {
		background: #2d2d2d;
	}
	.ttg-item img {
		opacity: 0.92;
	}
	.ttg-item:hover img {
		opacity: 1;
	}
}

body.night-mode .ttg-item,
body.dark-mode .ttg-item,
body.dark-theme .ttg-item {
	background: #2d2d2d;
}

body.night-mode .ttg-item img,
body.dark-mode .ttg-item img,
body.dark-theme .ttg-item img {
	opacity: 0.92;
}

body.night-mode .ttg-item:hover img,
body.dark-mode .ttg-item:hover img,
body.dark-theme .ttg-item:hover img {
	opacity: 1;
}

/* ───── Override default WP gallery styles when plugin active ───── */
.ttg-gallery .gallery-item,
.ttg-gallery .gallery-icon,
.ttg-gallery .gallery-caption {
	all: unset;
}

/* ───── Self-contained Lightbox ───── */
.ttg-lightbox {
	display: none;
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	z-index: 100000;
}
.ttg-lightbox-open {
	display: block;
}

.ttg-lightbox-bg {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: rgba(0, 0, 0, 0.92);
}

.ttg-lightbox-inner {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	max-width: 90vw;
	max-height: 90vh;
	display: flex;
	flex-direction: column;
	align-items: center;
}

.ttg-lightbox-img {
	max-width: 90vw;
	max-height: 80vh;
	object-fit: contain;
	border-radius: 4px;
	box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}

.ttg-lightbox-caption {
	color: #fff;
	font-size: 0.9rem;
	text-align: center;
	padding: 12px 8px 0;
	max-width: 80vw;
	line-height: 1.4;
	word-wrap: break-word;
}

.ttg-lightbox-counter {
	color: #ccc;
	font-size: 0.8rem;
	text-align: center;
	padding: 8px 8px 0;
}

.ttg-lightbox-close,
.ttg-lightbox-prev,
.ttg-lightbox-next {
	position: absolute;
	z-index: 10;
	background: rgba(0, 0, 0, 0.4);
	border: none;
	color: #fff;
	cursor: pointer;
	font-size: 28px;
	line-height: 1;
	border-radius: 3px;
	transition: background 0.2s;
}
.ttg-lightbox-close:hover,
.ttg-lightbox-prev:hover,
.ttg-lightbox-next:hover {
	background: rgba(0, 0, 0, 0.7);
}

.ttg-lightbox-close {
	top: 16px;
	right: 16px;
	padding: 6px 14px;
	font-size: 32px;
}

.ttg-lightbox-prev {
	top: 50%;
	left: 10px;
	transform: translateY(-50%);
	padding: 16px 12px;
}
.ttg-lightbox-next {
	top: 50%;
	right: 10px;
	transform: translateY(-50%);
	padding: 16px 12px;
}

@media (max-width: 768px) {
	.ttg-lightbox-prev,
	.ttg-lightbox-next {
		padding: 12px 8px;
		font-size: 22px;
	}
	.ttg-lightbox-close {
		top: 8px;
		right: 8px;
		padding: 4px 12px;
		font-size: 26px;
	}
}
