/**
 * Custom Dynamic Gallery — Frontend styles.
 *
 * Mobile-first responsive grid + accessible modal popup with a fixed-size
 * dialog, image fit inside, and floating product card overlay.
 */

/* ===========================================================
   1. GRID — CSS columns for masonry layout
   Each image keeps its natural aspect ratio. width: 100%, height: auto.
   =========================================================== */

.cdg-gallery {
	column-count: var(--cdg-cols, 2);
	column-gap: 14px;
	margin: 1.5em 0;
}

.cdg-gallery.cdg-cols-1 { --cdg-cols: 1; }
.cdg-gallery.cdg-cols-2 { --cdg-cols: 2; }
.cdg-gallery.cdg-cols-3 { --cdg-cols: 3; }
.cdg-gallery.cdg-cols-4 { --cdg-cols: 4; }
.cdg-gallery.cdg-cols-5 { --cdg-cols: 5; }
.cdg-gallery.cdg-cols-6 { --cdg-cols: 6; }

.cdg-item {
	display: block;
	width: 100%;
	margin: 0 0 14px;
	cursor: pointer;
	overflow: hidden;
	border-radius: 8px;
	background: #f4f4f4;
	transition: transform 0.2s ease, box-shadow 0.2s ease;
	outline: none;
	-webkit-tap-highlight-color: transparent;
	/* Prevents an item from being split across two columns. */
	break-inside: avoid;
	page-break-inside: avoid;
	-webkit-column-break-inside: avoid;
}
.cdg-item:hover,
.cdg-item:focus-visible {
	transform: translateY(-2px);
	box-shadow: 0 6px 18px rgba(0, 0, 0, 0.14);
}
.cdg-item:focus-visible {
	box-shadow: 0 0 0 3px #2271b1, 0 6px 18px rgba(0, 0, 0, 0.14);
}
.cdg-item-inner {
	position: relative;
	overflow: hidden;
	line-height: 0; /* removes inline-image baseline gap */
}
.cdg-item-inner img {
	width: 100%;
	height: auto;
	display: block;
	transition: transform 0.4s ease;
}
.cdg-item:hover .cdg-item-inner img {
	transform: scale(1.04);
}

.cdg-gallery-empty {
	padding: 30px;
	background: #f7f7f7;
	border: 1px dashed #ccc;
	text-align: center;
	color: #555;
	border-radius: 6px;
}

/* Tablet landscape */
@media (max-width: 1024px) {
	.cdg-gallery { column-gap: 12px; }
	.cdg-item    { margin-bottom: 12px; }
	.cdg-gallery.cdg-cols-6 { column-count: 5; }
	.cdg-gallery.cdg-cols-5 { column-count: 4; }
}

/* Tablet portrait */
@media (max-width: 768px) {
	.cdg-gallery { column-gap: 10px; margin: 1em 0; }
	.cdg-item    { margin-bottom: 10px; }
	.cdg-gallery.cdg-cols-6,
	.cdg-gallery.cdg-cols-5,
	.cdg-gallery.cdg-cols-4,
	.cdg-gallery.cdg-cols-3 { column-count: 3; }
	.cdg-gallery.cdg-cols-2 { column-count: 2; }
	.cdg-gallery.cdg-cols-1 { column-count: 1; }
}

/* Mobile — single column */
@media (max-width: 600px) {
	.cdg-gallery { column-gap: 12px; }
	.cdg-item    { margin-bottom: 12px; }
	.cdg-gallery.cdg-cols-6,
	.cdg-gallery.cdg-cols-5,
	.cdg-gallery.cdg-cols-4,
	.cdg-gallery.cdg-cols-3,
	.cdg-gallery.cdg-cols-2,
	.cdg-gallery.cdg-cols-1 {
		column-count: 1;
	}
}

@media (max-width: 380px) {
	.cdg-gallery { column-gap: 10px; }
	.cdg-item    { margin-bottom: 10px; }
}

/* ===========================================================
   2. MODAL — fixed dialog, image fits inside
   =========================================================== */

.cdg-modal {
	position: fixed;
	inset: 0;
	z-index: 99999;
	display: none;
	align-items: center;
	justify-content: center;
	padding: 40px 60px;
}
.cdg-modal.is-open {
	display: flex;
}

.cdg-modal-overlay {
	position: absolute;
	inset: 0;
	background: rgba(60, 60, 60, 0.92);
	cursor: pointer;
}

/* Nav buttons live OUTSIDE the dialog (sit on the dark overlay area). */
.cdg-modal-close,
.cdg-modal-prev,
.cdg-modal-next {
	position: absolute;
	z-index: 10;
	background: #1d1d1d;
	color: #fff;
	border: 0;
	width: 44px;
	height: 44px;
	border-radius: 50%;
	font-size: 22px;
	line-height: 1;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background 0.15s ease, transform 0.15s ease;
	-webkit-tap-highlight-color: transparent;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
.cdg-modal-close:hover,
.cdg-modal-prev:hover,
.cdg-modal-next:hover {
	background: #000;
	transform: scale(1.05);
}
.cdg-modal-close { top: 24px; right: 24px; }
.cdg-modal-prev  { top: 50%; left: 16px;  transform: translateY(-50%); }
.cdg-modal-next  { top: 50%; right: 16px; transform: translateY(-50%); }
.cdg-modal-prev:hover { transform: translateY(-50%) scale(1.05); }
.cdg-modal-next:hover { transform: translateY(-50%) scale(1.05); }

/* The dialog: white frame, fixed proportions, image fits inside. */
.cdg-modal-dialog {
	position: relative;
	background: #fff;
	width: 100%;
	max-width: 1200px;
	height: 100%;
	max-height: 88vh;
	border-radius: 8px;
	overflow: hidden;
	box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
	animation: cdgFadeIn 0.2s ease-out;
	padding: 24px;
	box-sizing: border-box;
	display: flex;
	flex-direction: column;
}
@keyframes cdgFadeIn {
	from { opacity: 0; transform: scale(0.97); }
	to   { opacity: 1; transform: scale(1); }
}

/* The stage holds the image, centers it, letterboxes with neutral gray. */
.cdg-modal-stage {
	position: relative;
	flex: 1 1 auto;
	min-height: 0;
	background: #cfcfcf;
	border-radius: 6px;
	overflow: hidden;
	display: flex;
	align-items: center;
	justify-content: center;
}

.cdg-modal-image {
	max-width: 100%;
	max-height: 100%;
	width: auto;
	height: auto;
	object-fit: contain;
	display: block;
}

.cdg-modal-loading {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	color: #555;
	font-style: italic;
	background: rgba(207, 207, 207, 0.7);
	pointer-events: none;
	opacity: 0;
	transition: opacity 0.15s ease;
}
.cdg-modal-loading.is-visible {
	opacity: 1;
}

/* ===========================================================
   3. FLOATING PRODUCT CARD OVERLAY
   =========================================================== */

.cdg-modal-product-card {
	position: absolute;
	right: 20px;
	bottom: 20px;
	background: #fff;
	border-radius: 8px;
	box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
	padding: 16px 20px;
	min-width: 240px;
	max-width: 320px;
	z-index: 3;
}
.cdg-modal-product-card[hidden] {
	display: none;
}

.cdg-product-card-inner {
	display: flex;
	flex-direction: column;
	gap: 6px;
}

.cdg-product-card-title {
	margin: 0;
	font-size: 16px;
	font-weight: 600;
	color: #1d2327;
	line-height: 1.3;
	word-break: break-word;
}

.cdg-product-card-price {
	font-size: 15px;
	font-weight: 600;
	color: #2271b1;
	margin: 0;
}
.cdg-product-card-price del {
	color: #999;
	margin-right: 6px;
	font-weight: 400;
}
.cdg-product-card-price ins {
	text-decoration: none;
}

/* The Add to Cart pill inside the card */
.cdg-product-card-cart {
	margin-top: 8px;
	background: #1d1d1d;
	color: #fff;
	border: 0;
	padding: 10px 18px;
	border-radius: 6px;
	font-size: 14px;
	font-weight: 600;
	cursor: pointer;
	align-self: flex-start;
	transition: background 0.15s ease, opacity 0.15s ease;
	min-height: 40px;
	-webkit-tap-highlight-color: transparent;
}
.cdg-product-card-cart:hover:not(:disabled),
.cdg-product-card-cart:focus-visible:not(:disabled) {
	background: #000;
	outline: none;
}
.cdg-product-card-cart:disabled {
	cursor: not-allowed;
	opacity: 0.55;
}
.cdg-product-card-cart.is-loading {
	opacity: 0.85;
}
.cdg-product-card-cart.is-added {
	background: #00a32a;
}

/* Pager when an image has multiple linked products. */
.cdg-product-card-pager {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	margin-top: 8px;
	padding-top: 10px;
	border-top: 1px solid #eee;
}
.cdg-product-card-pager[hidden] { display: none; }
.cdg-product-card-pager .cdg-card-prev,
.cdg-product-card-pager .cdg-card-next {
	background: #f0f0f1;
	border: 0;
	width: 28px;
	height: 28px;
	border-radius: 50%;
	cursor: pointer;
	font-size: 14px;
	color: #1d2327;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background 0.15s ease;
}
.cdg-product-card-pager .cdg-card-prev:hover,
.cdg-product-card-pager .cdg-card-next:hover {
	background: #dcdcde;
}
.cdg-card-count {
	font-size: 12px;
	color: #666;
}

.cdg-no-products-card {
	color: #888;
	font-style: italic;
	font-size: 13px;
}

/* ===========================================================
   4. RESPONSIVE — MODAL
   =========================================================== */

/* Tablet landscape */
@media (max-width: 1024px) {
	.cdg-modal { padding: 32px 50px; }
	.cdg-modal-dialog {
		max-width: 95vw;
		padding: 20px;
	}
}

/* Tablet portrait */
@media (max-width: 768px) {
	.cdg-modal { padding: 24px 36px; }
	.cdg-modal-dialog {
		max-height: 92vh;
		padding: 16px;
		border-radius: 6px;
	}
	.cdg-modal-close { top: 14px; right: 14px; }
	.cdg-modal-prev  { left: 6px; }
	.cdg-modal-next  { right: 6px; }

	.cdg-modal-product-card {
		right: 12px;
		bottom: 12px;
		min-width: 200px;
		max-width: 260px;
		padding: 12px 14px;
	}
	.cdg-product-card-title { font-size: 14px; }
	.cdg-product-card-price { font-size: 14px; }
	.cdg-product-card-cart  { padding: 8px 14px; font-size: 13px; min-height: 36px; }
}

/* Mobile — full screen, product card sits along the bottom edge */
@media (max-width: 600px) {
	.cdg-modal { padding: 0; }
	.cdg-modal-dialog {
		max-width: 100%;
		max-height: 100vh;
		height: 100vh;
		border-radius: 0;
		padding: 56px 12px 12px; /* extra top padding so close btn doesn't overlap stage */
	}

	.cdg-modal-close {
		top: 10px;
		right: 10px;
		width: 40px;
		height: 40px;
		font-size: 20px;
	}
	.cdg-modal-prev,
	.cdg-modal-next {
		width: 40px;
		height: 40px;
		font-size: 20px;
		top: 50%;
		bottom: auto;
		transform: translateY(-50%);
	}
	.cdg-modal-prev:hover,
	.cdg-modal-next:hover {
		transform: translateY(-50%) scale(1.05);
	}
	.cdg-modal-prev { left: 8px; }
	.cdg-modal-next { right: 8px; }

	/* On mobile, the product card spans the bottom of the stage */
	.cdg-modal-product-card {
		left: 12px;
		right: 12px;
		bottom: 12px;
		max-width: none;
		min-width: 0;
		padding: 12px 14px;
	}
	.cdg-product-card-cart { width: 100%; }
}

@media (max-width: 380px) {
	.cdg-product-card-title { font-size: 13px; }
}

/* ===========================================================
   5. TOAST NOTIFICATIONS
   =========================================================== */

.cdg-toast-container {
	position: fixed;
	bottom: 24px;
	left: 50%;
	transform: translateX(-50%);
	z-index: 100000;
	display: flex;
	flex-direction: column;
	gap: 8px;
	pointer-events: none;
	max-width: 90vw;
}
.cdg-toast {
	background: #1d2327;
	color: #fff;
	padding: 12px 18px;
	border-radius: 6px;
	font-size: 14px;
	font-weight: 500;
	box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
	opacity: 0;
	transform: translateY(20px);
	transition: opacity 0.25s ease, transform 0.25s ease;
	pointer-events: auto;
	min-width: 220px;
	text-align: center;
}
.cdg-toast.is-visible {
	opacity: 1;
	transform: translateY(0);
}
.cdg-toast-success { background: #00a32a; }
.cdg-toast-error   { background: #d63638; }
.cdg-toast-info    { background: #2271b1; }

@media (max-width: 600px) {
	.cdg-toast-container {
		bottom: 16px;
		left: 16px;
		right: 16px;
		transform: none;
		max-width: none;
	}
	.cdg-toast {
		min-width: 0;
		width: 100%;
	}
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
	.cdg-item,
	.cdg-item-inner img,
	.cdg-modal-dialog,
	.cdg-product-card-cart,
	.cdg-toast {
		transition: none !important;
		animation: none !important;
	}
}
