.mgi-product-gallery {
	--mgi-gallery-accent: #159968;
	--mgi-gallery-border: #d9e2de;
	--mgi-gallery-control-bg: rgba(78, 86, 84, 0.62);
	--mgi-gallery-thumbs-desktop: 6;
	--mgi-gallery-thumbs-mobile: 5;
	--mgi-gallery-thumb-gap: 8px;
	--mgi-gallery-thumb-gap-mobile: 7px;
	position: relative;
	box-sizing: border-box;
	min-width: 0;
}

.woocommerce div.product div.images.mgi-product-gallery {
	position: relative;
	float: left;
	width: 48%;
	margin: 0 0 2em;
	opacity: 1 !important;
}

.mgi-product-gallery *,
.mgi-product-gallery *::before,
.mgi-product-gallery *::after {
	box-sizing: border-box;
}

.mgi-product-gallery [hidden] {
	display: none !important;
}

.mgi-product-gallery button {
	font: inherit;
	-webkit-appearance: none;
	appearance: none;
}

.mgi-product-gallery__stage {
	position: relative;
	width: 100%;
	aspect-ratio: 1 / 1;
	overflow: hidden;
	border: 2px solid var(--mgi-gallery-accent);
	border-radius: 3px;
	background: #fff;
	box-shadow: 0 1px 2px rgba(20, 40, 32, 0.08);
	touch-action: pan-y pinch-zoom;
	isolation: isolate;
}

.mgi-product-gallery__stage:focus-visible {
	outline: 2px solid var(--mgi-gallery-accent);
	outline-offset: 3px;
}

.mgi-product-gallery__slides,
.mgi-product-gallery__slide,
.mgi-product-gallery__media-button {
	position: absolute;
	inset: 0;
	float: none !important;
	width: 100% !important;
	max-width: none !important;
	height: 100% !important;
	min-width: 0;
	margin: 0 !important;
	padding: 0 !important;
}

.mgi-product-gallery__slides {
	overflow: hidden;
}

.mgi-product-gallery__slide {
	display: block;
	z-index: 1;
}

.mgi-product-gallery__slide.is-active {
	z-index: 2;
}

.mgi-product-gallery__media-button {
	display: flex;
	align-items: center;
	justify-content: center;
	overflow: hidden;
	border: 0 !important;
	border-radius: 0 !important;
	background: #fff !important;
	color: inherit;
	line-height: 0;
	text-decoration: none;
	cursor: zoom-in;
	box-shadow: none !important;
}

.mgi-product-gallery__media-button:focus-visible {
	outline: 3px solid var(--mgi-gallery-accent);
	outline-offset: -3px;
}

.mgi-product-gallery__video-button {
	background: #0c0f0e !important;
	cursor: pointer;
}

.woocommerce div.product div.images.mgi-product-gallery img.mgi-product-gallery__image,
.mgi-product-gallery img.mgi-product-gallery__image {
	display: block;
	float: none !important;
	width: 100% !important;
	max-width: none !important;
	height: 100% !important;
	margin: 0 !important;
	padding: 0;
	object-fit: contain;
	object-position: center;
	border: 0;
	background: #fff;
	box-shadow: none;
	user-select: none;
	-webkit-user-drag: none;
}

.mgi-product-gallery__video-button .mgi-product-gallery__image {
	background: #0c0f0e !important;
	opacity: 0.94;
}

.mgi-product-gallery__video-placeholder,
.mgi-product-gallery__thumb-placeholder {
	display: block;
	width: 100%;
	height: 100%;
	background: linear-gradient(135deg, #202522, #070908);
}

.mgi-product-gallery__play {
	display: grid;
	position: absolute;
	top: 50%;
	left: 50%;
	width: 70px;
	height: 70px;
	transform: translate(-50%, -50%);
	place-items: center;
	border: 2px solid rgba(255, 255, 255, 0.94);
	border-radius: 50%;
	background: rgba(0, 0, 0, 0.67);
	color: #fff;
	box-shadow: 0 8px 26px rgba(0, 0, 0, 0.28);
	pointer-events: none;
}

.mgi-product-gallery__play svg {
	width: 30px;
	height: 30px;
	margin-left: 4px;
	fill: currentColor;
}

.mgi-product-gallery__video-title {
	position: absolute;
	top: 14px;
	left: 14px;
	max-width: calc(100% - 82px);
	padding: 6px 10px;
	overflow: hidden;
	border-radius: 999px;
	background: rgba(0, 0, 0, 0.68);
	color: #fff;
	font-size: 12px;
	font-weight: 600;
	line-height: 1.2;
	letter-spacing: 0.02em;
	text-overflow: ellipsis;
	text-transform: uppercase;
	white-space: nowrap;
	pointer-events: none;
}

.mgi-product-gallery__arrow,
.mgi-product-gallery__expand {
	display: grid;
	position: absolute;
	z-index: 32;
	place-items: center;
	margin: 0;
	padding: 0;
	border: 0 !important;
	border-radius: 999px !important;
	background: var(--mgi-gallery-control-bg) !important;
	color: #fff !important;
	cursor: pointer;
	box-shadow: 0 2px 9px rgba(0, 0, 0, 0.18) !important;
}

.mgi-product-gallery__arrow {
	border-radius: 0 !important;
	background: var(--mgi-gallery-control-bg) !important;
	box-shadow: none !important;
}

.mgi-product-gallery__expand {
	border-radius: 999px !important;
}

.mgi-product-gallery__arrow svg,
.mgi-product-gallery__expand svg,
.mgi-product-gallery__modal-close svg,
.mgi-product-gallery__modal-arrow svg {
	width: 24px;
	height: 24px;
	fill: none;
	stroke: currentColor;
	stroke-width: 2;
	stroke-linecap: round;
	stroke-linejoin: round;
}

.mgi-product-gallery__arrow {
	top: 50%;
	width: 38px;
	height: 46px;
	transform: translateY(-50%);
	backdrop-filter: blur(2px);
	transition: background-color 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease, opacity 0.18s ease;
}

.mgi-product-gallery__arrow--previous {
	left: 0;
}

.mgi-product-gallery__arrow--next {
	right: 0;
}

.mgi-product-gallery__expand {
	right: 12px;
	bottom: 12px;
	width: 34px;
	height: 34px;
	background: var(--mgi-gallery-control-bg) !important;
	backdrop-filter: blur(2px);
	transition: background-color 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease, opacity 0.18s ease;
}

.mgi-product-gallery__expand svg {
	width: 21px;
	height: 21px;
}

.mgi-product-gallery__arrow:hover,
.mgi-product-gallery__arrow:focus-visible {
	background: rgba(58, 66, 64, 0.82) !important;
	color: #fff !important;
	outline: 1px solid rgba(255, 255, 255, 0.78);
	outline-offset: -1px;
	box-shadow: none !important;
}

.mgi-product-gallery__expand:hover,
.mgi-product-gallery__expand:focus-visible {
	background: rgba(58, 66, 64, 0.82) !important;
	color: #fff !important;
	outline: 1px solid rgba(255, 255, 255, 0.78);
	outline-offset: -1px;
	box-shadow: none !important;
}

.mgi-product-gallery__arrow:hover {
	transform: translateY(-50%) scale(1.03);
}

.mgi-product-gallery__expand:hover {
	transform: scale(1.03);
}

.mgi-product-gallery__counter {
	position: absolute;
	z-index: 31;
	bottom: 14px;
	left: 14px;
	min-width: 48px;
	padding: 6px 10px;
	border-radius: 999px;
	background: var(--mgi-gallery-control-bg);
	color: #fff;
	font-size: 12px;
	font-weight: 500;
	line-height: 1.15;
	text-align: center;
	pointer-events: none;
}

.mgi-product-gallery__stage > .wpshare247-overlay-text {
	z-index: 20;
}

.mgi-product-gallery__thumbs {
	display: flex;
	gap: var(--mgi-gallery-thumb-gap);
	align-items: stretch;
	width: 100%;
	margin-top: 10px;
	overflow-x: auto;
	overflow-y: hidden;
	padding: 2px 1px 4px;
	scrollbar-width: none;
	scroll-snap-type: x proximity;
	overscroll-behavior-x: contain;
	-webkit-overflow-scrolling: touch;
}

.mgi-product-gallery__thumbs::-webkit-scrollbar {
	display: none;
}

.mgi-product-gallery__thumb {
	position: relative;
	flex: 0 0 calc((100% - (var(--mgi-gallery-thumb-gap) * (var(--mgi-gallery-thumbs-desktop) - 1))) / var(--mgi-gallery-thumbs-desktop));
	width: calc((100% - (var(--mgi-gallery-thumb-gap) * (var(--mgi-gallery-thumbs-desktop) - 1))) / var(--mgi-gallery-thumbs-desktop));
	min-width: 0;
	max-width: none;
	height: auto;
	aspect-ratio: 1 / 1;
	margin: 0 !important;
	padding: 2px !important;
	overflow: hidden;
	border: 1px solid var(--mgi-gallery-border) !important;
	border-radius: 4px !important;
	background: #fff !important;
	cursor: pointer;
	box-shadow: none !important;
	scroll-snap-align: start;
}

.mgi-product-gallery__thumb img {
	display: block;
	width: 100% !important;
	height: 100% !important;
	margin: 0 !important;
	object-fit: cover;
	object-position: center;
	border: 0;
	user-select: none;
	-webkit-user-drag: none;
}

.mgi-product-gallery__thumb:hover {
	border-color: #8ebdac !important;
}

.mgi-product-gallery__thumb.is-active {
	border-color: var(--mgi-gallery-accent) !important;
	box-shadow: 0 0 0 1px var(--mgi-gallery-accent) !important;
}

.mgi-product-gallery__thumb:focus-visible {
	outline: 2px solid var(--mgi-gallery-accent);
	outline-offset: 2px;
}

.mgi-product-gallery__thumb-play {
	display: grid;
	position: absolute;
	top: 50%;
	left: 50%;
	width: 34px;
	height: 34px;
	transform: translate(-50%, -50%);
	place-items: center;
	border: 1px solid rgba(255, 255, 255, 0.9);
	border-radius: 50%;
	background: rgba(0, 0, 0, 0.73);
	color: #fff;
	box-shadow: 0 2px 9px rgba(0, 0, 0, 0.24);
	pointer-events: none;
}

.mgi-product-gallery__thumb-play svg {
	width: 17px;
	height: 17px;
	margin-left: 2px;
	fill: currentColor;
}

.mgi-product-gallery__modal {
	position: fixed;
	z-index: 2147483000;
	inset: 0;
}

.mgi-product-gallery__modal-backdrop {
	position: absolute;
	inset: 0;
	background: rgba(9, 26, 39, 0.92);
	backdrop-filter: none;
}

.mgi-product-gallery__modal-close-zone {
	display: none;
	position: fixed;
	z-index: 2;
	right: 0;
	left: 0;
	background: transparent;
	pointer-events: none;
}

.mgi-product-gallery__modal-close-zone--top {
	top: 0;
}

.mgi-product-gallery__modal-dialog {
	display: flex;
	position: absolute;
	inset: 0;
	align-items: center;
	justify-content: center;
	padding: max(58px, env(safe-area-inset-top)) 74px max(68px, env(safe-area-inset-bottom));
	pointer-events: none;
}

.mgi-product-gallery__modal-media {
	display: flex;
	width: min(1180px, 100%);
	height: min(80vh, 880px);
	align-items: center;
	justify-content: center;
	touch-action: pan-y pinch-zoom;
	pointer-events: auto;
}

.mgi-product-gallery__modal-image {
	display: block;
	width: auto;
	height: auto;
	max-width: 100%;
	max-height: 100%;
	margin: 0;
	object-fit: contain;
	background: transparent;
	user-select: none;
	-webkit-user-drag: none;
}

.mgi-product-gallery__modal-iframe {
	display: block;
	width: min(1100px, 100%);
	max-height: 80vh;
	border: 0;
	border-radius: 4px;
	background: #000;
	aspect-ratio: 16 / 9;
	box-shadow: 0 16px 50px rgba(0, 0, 0, 0.35);
}

.mgi-product-gallery__modal-video {
	display: block;
	width: auto;
	height: auto;
	max-width: 100%;
	max-height: 80vh;
	border: 0;
	border-radius: 4px;
	background: #000;
	box-shadow: 0 16px 50px rgba(0, 0, 0, 0.35);
}

.mgi-product-gallery__modal-close,
.mgi-product-gallery__modal-arrow {
	display: grid;
	position: absolute;
	z-index: 3;
	place-items: center;
	margin: 0;
	padding: 0;
	border: 0 !important;
	border-radius: 999px !important;
	background: var(--mgi-gallery-control-bg) !important;
	color: #fff !important;
	cursor: pointer;
	pointer-events: auto;
	box-shadow: 0 2px 9px rgba(0, 0, 0, 0.18) !important;
	backdrop-filter: blur(2px);
	transition: background-color 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease, opacity 0.18s ease;
}

.mgi-product-gallery__modal-arrow {
	border-radius: 0 !important;
	background: var(--mgi-gallery-control-bg) !important;
	box-shadow: none !important;
}

.mgi-product-gallery__modal-close {
	border-radius: 999px !important;
	background: var(--mgi-gallery-control-bg) !important;
}

.mgi-product-gallery__modal-close {
	top: max(12px, env(safe-area-inset-top));
	right: max(8px, env(safe-area-inset-right));
	width: 44px;
	height: 44px;
}

.mgi-product-gallery__modal-close svg {
	width: 25px;
	height: 25px;
}

.mgi-product-gallery__modal-arrow {
	top: 50%;
	width: 38px;
	height: 46px;
	transform: translateY(-50%);
}

.mgi-product-gallery__modal-arrow--previous {
	left: max(0px, env(safe-area-inset-left));
}

.mgi-product-gallery__modal-arrow--next {
	right: max(0px, env(safe-area-inset-right));
}

.mgi-product-gallery__modal-arrow:hover,
.mgi-product-gallery__modal-arrow:focus-visible {
	background: rgba(58, 66, 64, 0.82) !important;
	outline: 1px solid rgba(255, 255, 255, 0.78);
	outline-offset: -1px;
	box-shadow: none !important;
}

.mgi-product-gallery__modal-close:hover,
.mgi-product-gallery__modal-close:focus-visible {
	background: rgba(58, 66, 64, 0.82) !important;
	outline: 1px solid rgba(255, 255, 255, 0.78);
	outline-offset: -1px;
	box-shadow: none !important;
}


body.mgi-product-gallery-modal-open {
	position: fixed;
	width: 100%;
	height: 100%;
	overflow: hidden;
}

@media (min-width: 991px) {
	.woocommerce div.product div.images.mgi-product-gallery {
		width: 50%;
	}
}

.mgi-product-gallery__arrow,
.mgi-product-gallery__expand,
.mgi-product-gallery__modal-close,
.mgi-product-gallery__modal-arrow {
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
}

.mgi-product-gallery.mgi-controls-visible .mgi-product-gallery__arrow,
.mgi-product-gallery.mgi-controls-visible .mgi-product-gallery__expand,
.mgi-product-gallery.mgi-controls-visible .mgi-product-gallery__counter,
.mgi-product-gallery__stage:focus-within .mgi-product-gallery__arrow,
.mgi-product-gallery__stage:focus-within .mgi-product-gallery__expand,
.mgi-product-gallery__stage:focus-within .mgi-product-gallery__counter {
	opacity: 1;
	visibility: visible;
	pointer-events: auto;
}

.mgi-product-gallery__counter {
	transition: opacity 0.18s ease, visibility 0.18s ease;
}

.mgi-product-gallery__modal.mgi-modal-controls-visible .mgi-product-gallery__modal-close,
.mgi-product-gallery__modal.mgi-modal-controls-visible .mgi-product-gallery__modal-arrow,
.mgi-product-gallery__modal:focus-within .mgi-product-gallery__modal-close,
.mgi-product-gallery__modal:focus-within .mgi-product-gallery__modal-arrow {
	opacity: 1;
	visibility: visible;
	pointer-events: auto;
}


@media (max-width: 768px) {
	.woocommerce div.product div.images.mgi-product-gallery {
		float: none;
		width: 100%;
		margin-bottom: 22px;
	}

	.mgi-product-gallery__stage {
		width: 100%;
		border-width: 1.5px;
	}

	.mgi-product-gallery__arrow {
		width: 36px;
		height: 42px;
	}

	.mgi-product-gallery__arrow--previous {
		left: 0;
	}

	.mgi-product-gallery__arrow--next {
		right: 0;
	}

	.mgi-product-gallery__expand {
		right: 9px;
		bottom: 9px;
		width: 34px;
		height: 34px;
	}

	.mgi-product-gallery__counter {
		bottom: 10px;
		left: 10px;
	}

	.mgi-product-gallery__thumbs {
		gap: var(--mgi-gallery-thumb-gap-mobile);
		margin-top: 8px;
	}

	.mgi-product-gallery__thumb {
		flex-basis: calc((100% - (var(--mgi-gallery-thumb-gap-mobile) * (var(--mgi-gallery-thumbs-mobile) - 1))) / var(--mgi-gallery-thumbs-mobile));
		width: calc((100% - (var(--mgi-gallery-thumb-gap-mobile) * (var(--mgi-gallery-thumbs-mobile) - 1))) / var(--mgi-gallery-thumbs-mobile));
		min-width: 0;
		max-width: none;
		height: auto;
		aspect-ratio: 1 / 1;
	}

	.mgi-product-gallery__play {
		width: 60px;
		height: 60px;
	}

	.mgi-product-gallery__play svg {
		width: 25px;
		height: 25px;
	}

	.mgi-product-gallery__video-title {
		top: 10px;
		left: 10px;
		max-width: calc(100% - 68px);
		font-size: 11px;
	}

	.mgi-product-gallery__modal-dialog {
		padding: max(58px, env(safe-area-inset-top)) 12px max(72px, env(safe-area-inset-bottom));
	}

	.mgi-product-gallery__modal-media {
		width: 100%;
		height: calc(100dvh - 150px);
		max-height: calc(100svh - 150px);
	}

	.mgi-product-gallery__modal-close-zone {
		display: block;
		pointer-events: auto;
	}

	.mgi-product-gallery__modal-image {
		touch-action: pan-y pinch-zoom;
	}

	.mgi-product-gallery__modal-iframe {
		width: 100%;
		max-height: calc(100dvh - 174px);
	}

	.mgi-product-gallery__modal-video {
		max-width: 100%;
		max-height: calc(100dvh - 174px);
	}

	.mgi-product-gallery__modal-arrow {
		top: 50%;
		bottom: auto;
		width: 36px;
		height: 42px;
		transform: translateY(-50%);
	}

	.mgi-product-gallery__modal-arrow--previous {
		left: max(0px, env(safe-area-inset-left));
	}

	.mgi-product-gallery__modal-arrow--next {
		right: max(0px, env(safe-area-inset-right));
	}

}

@media (max-width: 420px) {
	.mgi-product-gallery__thumb {
		flex-basis: calc((100% - (var(--mgi-gallery-thumb-gap-mobile) * (var(--mgi-gallery-thumbs-mobile) - 1))) / var(--mgi-gallery-thumbs-mobile));
		width: calc((100% - (var(--mgi-gallery-thumb-gap-mobile) * (var(--mgi-gallery-thumbs-mobile) - 1))) / var(--mgi-gallery-thumbs-mobile));
		min-width: 0;
		height: auto;
		aspect-ratio: 1 / 1;
	}

	.mgi-product-gallery__thumb-play {
		width: 30px;
		height: 30px;
	}
}

@media (max-height: 520px) and (orientation: landscape) {
	.mgi-product-gallery__modal-dialog {
		padding: 48px 68px 50px;
	}

	.mgi-product-gallery__modal-media,
	.mgi-product-gallery__modal-iframe,
	.mgi-product-gallery__modal-video {
		max-height: calc(100dvh - 98px);
		height: calc(100dvh - 98px);
	}

}

@media (prefers-reduced-motion: reduce) {
	.mgi-product-gallery *,
	.mgi-product-gallery *::before,
	.mgi-product-gallery *::after {
		scroll-behavior: auto !important;
		transition: none !important;
	}
}

/* Kéo/vuốt thanh thumbnail: desktop dùng chuột, mobile dùng cuộn cảm ứng native. */
@media (hover: hover) and (pointer: fine) {
	.mgi-product-gallery__thumbs {
		user-select: none;
	}

	.mgi-product-gallery__thumbs.is-scrollable {
		cursor: grab;
	}

	.mgi-product-gallery__thumbs.is-dragging {
		cursor: grabbing;
		scroll-snap-type: none;
	}

	.mgi-product-gallery__thumbs.is-dragging .mgi-product-gallery__thumb {
		pointer-events: none;
	}

	.mgi-product-gallery__modal-image {
		cursor: grab;
	}

	.mgi-product-gallery__modal.is-dragging .mgi-product-gallery__modal-image {
		cursor: grabbing;
	}
}

/* Video phát trực tiếp trong khung media chính; lightbox/phóng to giữ nguyên. */
.mgi-product-gallery__inline-video,
.mgi-product-gallery__inline-iframe {
	display: block;
	position: absolute;
	inset: 0;
	z-index: 4;
	width: 100%;
	height: 100%;
	margin: 0;
	border: 0;
	background: #000;
}

.mgi-product-gallery__inline-video {
	object-fit: contain;
}


/* Đồng bộ lightbox với tông nền phủ của popup Mã giảm giá. */
.mgi-product-gallery__modal-backdrop {
	background: rgba(9, 26, 39, 0.92);
	backdrop-filter: none;
}

/* Desktop: scrollbar ngang rõ ràng cho thumbnail rail. Dùng chính scrollbar làm đường phân tách, không thêm line giả. */
@media (min-width: 769px) {
	.mgi-product-gallery__thumbs {
		margin-bottom: 14px;
		padding-bottom: 8px;
		scrollbar-width: thin;
		scrollbar-color: #1f5f49 #e7eeea;
	}

	.mgi-product-gallery__thumbs::-webkit-scrollbar {
		display: block;
		height: 8px;
	}

	.mgi-product-gallery__thumbs::-webkit-scrollbar-track {
		background: #e7eeea;
		border-radius: 999px;
	}

	.mgi-product-gallery__thumbs::-webkit-scrollbar-thumb {
		background: #1f5f49;
		border: 1px solid #e7eeea;
		border-radius: 999px;
	}

	.mgi-product-gallery__thumbs::-webkit-scrollbar-thumb:hover {
		background: #154936;
	}
}

/* Mobile: giữ giao diện gọn, vuốt tay trực tiếp và ẩn scrollbar. */
@media (max-width: 768px) {
	.mgi-product-gallery__thumbs {
		scrollbar-width: none;
	}

	.mgi-product-gallery__thumbs::-webkit-scrollbar {
		display: none;
	}
}
