.ag-gallery {
	--ag-columns: 3;
	--ag-gap: 1rem;
	--ag-radius: 6px;
	--ag-bg: #f3f4f6;
}
.ag-gallery__list {
	list-style: none;
	margin: 0;
	padding: 0;
	display: grid;
	grid-template-columns: repeat(var(--ag-columns), minmax(0, 1fr));
	column-gap: var(--ag-column-gap, var(--ag-gap));
	row-gap: var(--ag-row-gap, var(--ag-gap));
}
@media (max-width: 782px) {
	.ag-gallery__list { grid-template-columns: repeat(min(var(--ag-columns), 2), minmax(0, 1fr)); }
}
@media (max-width: 480px) {
	.ag-gallery__list { grid-template-columns: 1fr; }
}
.ag-gallery__item { margin: 0; padding: 0; }
.ag-gallery__figure { margin: 0; display: flex; flex-direction: column; height: 100%; }
.ag-gallery__link { display: block; text-decoration: none; color: inherit; }
.ag-gallery__thumb {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	aspect-ratio: 4 / 3;
	overflow: hidden;
	border-radius: var(--ag-radius);
	background: var(--ag-bg);
}
.ag-gallery__image { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .25s ease; }
.ag-gallery__image--icon { width: auto; height: 50%; object-fit: contain; }
.ag-gallery__link:hover .ag-gallery__image,
.ag-gallery__link:focus-visible .ag-gallery__image { transform: scale(1.04); }
.ag-gallery__link:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; border-radius: var(--ag-radius); }
.ag-gallery__badge {
	position: absolute; right: .5rem; bottom: .5rem;
	padding: .1rem .45rem; border-radius: 3px;
	font-size: .7rem; font-weight: 600; letter-spacing: .03em;
	background: rgba(0,0,0,.65); color: #fff;
}
.ag-gallery__caption { display: flex; flex-direction: column; gap: .15rem; padding-top: .5rem; font-size: var(--ag-caption-font-size, .9rem); line-height: 1.35; }
.ag-gallery__title { font-weight: 600; overflow-wrap: anywhere; }
.ag-gallery__text { opacity: .85; }
.ag-gallery__meta { opacity: .6; font-size: .89em; }
.ag-gallery__notice { padding: .75rem 1rem; border-left: 4px solid #d63638; background: #fcf0f1; }

/* ---------- Стили подписи ---------- */

/* card — подпись в карточке с фоном */
.ag-gallery--caption-card .ag-gallery__figure {
	overflow: hidden;
	border: 1px solid rgba(0,0,0,.08);
	border-radius: var(--ag-radius);
	background: #fff;
	box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.ag-gallery--caption-card .ag-gallery__thumb { border-radius: 0; }
.ag-gallery--caption-card .ag-gallery__link:focus-visible { outline-offset: -2px; border-radius: 0; }
.ag-gallery--caption-card .ag-gallery__caption { flex: 1; padding: .6rem .75rem .75rem; }

/* overlay и hover — подпись поверх миниатюры */
.ag-gallery--caption-overlay .ag-gallery__figure,
.ag-gallery--caption-hover .ag-gallery__figure {
	position: relative;
	overflow: hidden;
	border-radius: var(--ag-radius);
}
.ag-gallery--caption-overlay .ag-gallery__caption,
.ag-gallery--caption-hover .ag-gallery__caption {
	position: absolute;
	left: 0; right: 0; bottom: 0;
	padding: 2rem .75rem .65rem;
	color: #fff;
	background: linear-gradient(to top, rgba(0,0,0,.78), rgba(0,0,0,.45) 60%, transparent);
	pointer-events: none; /* клик проходит на ссылку под подписью */
}
.ag-gallery--caption-overlay .ag-gallery__text,
.ag-gallery--caption-hover .ag-gallery__text {
	opacity: .9;
	display: -webkit-box;
	-webkit-line-clamp: var(--ag-text-lines, 2);
	line-clamp: var(--ag-text-lines, 2);
	-webkit-box-orient: vertical;
	overflow: hidden;
}
.ag-gallery--caption-overlay .ag-gallery__meta,
.ag-gallery--caption-hover .ag-gallery__meta { opacity: .8; }
/* Метка типа файла переезжает наверх, чтобы не перекрываться подписью */
.ag-gallery--caption-overlay .ag-gallery__badge,
.ag-gallery--caption-hover .ag-gallery__badge { top: .5rem; bottom: auto; }

/* hover — подпись появляется при наведении или фокусе */
.ag-gallery--caption-hover .ag-gallery__caption {
	opacity: 0;
	transform: translateY(.5rem);
	transition: opacity .2s ease, transform .2s ease;
}
.ag-gallery--caption-hover .ag-gallery__figure:hover .ag-gallery__caption,
.ag-gallery--caption-hover .ag-gallery__figure:focus-within .ag-gallery__caption {
	opacity: 1;
	transform: none;
}
/* На сенсорных экранах наведения нет — показываем подпись всегда */
@media (hover: none) {
	.ag-gallery--caption-hover .ag-gallery__caption { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
	.ag-gallery--caption-hover .ag-gallery__caption { transition: none; }
}
.ag-gallery--caption-overlay .ag-gallery__link:focus-visible,
.ag-gallery--caption-hover .ag-gallery__link:focus-visible { outline-offset: -2px; }

/* ---------- Ограничение числа строк (с многоточием) ---------- */
.ag-gallery--clamp-title .ag-gallery__title,
.ag-gallery--clamp-text .ag-gallery__text {
	display: -webkit-box;
	-webkit-box-orient: vertical;
	overflow: hidden;
}
.ag-gallery--clamp-title .ag-gallery__title {
	-webkit-line-clamp: var(--ag-title-lines);
	line-clamp: var(--ag-title-lines);
	overflow-wrap: break-word;
}
.ag-gallery--clamp-text .ag-gallery__text {
	-webkit-line-clamp: var(--ag-text-lines);
	line-clamp: var(--ag-text-lines);
	overflow-wrap: break-word;
}

/* overlay / hover: без явной настройки название ограничено 2 строками, подпись не выходит за превью */
.ag-gallery--caption-overlay .ag-gallery__title,
.ag-gallery--caption-hover .ag-gallery__title {
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: var(--ag-title-lines, 2);
	line-clamp: var(--ag-title-lines, 2);
	overflow: hidden;
}
.ag-gallery--caption-overlay .ag-gallery__caption,
.ag-gallery--caption-hover .ag-gallery__caption {
	max-height: 100%;
	overflow: hidden;
}
