/* ==========================================================================
   Gifty Product Designer – inline studio on the product page.
   Uses Gifty tokens with fallbacks.
   ========================================================================== */

.gpd-studio, .gpd-left, .gpd-lightbox {
	--gpd-p: var(--g-purple, #7A00C8);
	--gpd-pd: var(--g-purple-dark, #5A0096);
	--gpd-soft: var(--g-purple-50, #F6EEFD);
	--gpd-y: var(--g-yellow, #FFD900);
	--gpd-ink: var(--g-ink, #1C1C1C);
	--gpd-muted: var(--g-muted, #5F5A66);
	--gpd-line: var(--g-line, #ECE6F2);
}
.gpd-studio {
	position: relative;
	flex: 1 1 100%;
	width: 100%;
	margin: 0 0 16px;
	padding: 16px;
	border: 1.5px solid #E8D9F8;
	border-radius: 20px;
	background: #fff;
	box-shadow: 0 10px 30px rgba(42, 0, 73, .06);
	box-sizing: border-box;
	scroll-margin-top: 110px;
}
.gpd-studio.has-error { border-color: #C62828; box-shadow: 0 0 0 4px rgba(198, 40, 40, .08); }

/* Head */
.gpd-studio__head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.gpd-studio__icon { flex: 0 0 42px; display: grid; place-items: center; width: 42px; height: 42px; border-radius: 12px; background: var(--gpd-p); color: #fff; }
.gpd-studio__titles { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.gpd-studio__title { font-size: 16.5px; color: var(--gpd-ink); line-height: 1.3; }
.gpd-studio__sub { font-size: 13.5px; color: var(--gpd-muted); line-height: 1.4; }
.gpd-studio__price { color: var(--gpd-p); font-weight: 700; white-space: nowrap; }
.gpd-req { color: #C62828; }

/* Body: stage + tools side by side when there is room */
.gpd-studio__body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.gpd-stage {
	position: relative;
	display: flex;
	flex-direction: column;
	align-items: center;
	padding: 10px;
	border-radius: 16px;
	background: #F8F4FC;
}
.gpd-canvas { display: block; max-width: 100%; border-radius: 12px; background: #fff; box-shadow: 0 6px 20px rgba(42, 0, 73, .1); touch-action: none; cursor: grab; outline: none; }
.gpd-canvas:active { cursor: grabbing; }
.gpd-canvas:focus-visible { box-shadow: 0 0 0 3px var(--gpd-y); }
.gpd-stage__hint { margin: 8px 0 0; font-size: 12px; color: var(--gpd-muted); text-align: center; }
.gpd-stage__cta {
	position: absolute;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 6px;
	padding: 4px;
	border-radius: 10px;
	background: rgba(255, 255, 255, .78);
	color: var(--gpd-p);
	font-weight: 700;
	font-size: 12.5px;
	line-height: 1.2;
	text-align: center;
	cursor: pointer;
	box-sizing: border-box;
	overflow: hidden;
	transition: background .2s ease;
}
.gpd-stage__cta:hover { background: rgba(255, 255, 255, .92); }
.gpd-stage__cta[hidden] { display: none; }
.gpd-stage__cta input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.gpd-stage__cta-icon { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; background: var(--gpd-p); color: #fff; box-shadow: 0 6px 14px rgba(122, 0, 200, .3); }
.gpd-stage__cta.is-small > span:last-child { display: none; }
.gpd-stage__cta.is-small .gpd-stage__cta-icon { width: 30px; height: 30px; }

/* Tools */
.gpd-panel { min-width: 0; }
.gpd-tabs { display: grid; grid-auto-flow: column; gap: 6px; margin-bottom: 12px; padding: 5px; border-radius: 999px; background: #F4F0F8; }
.gpd-tabs button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; border: 0; border-radius: 999px; background: transparent; color: var(--gpd-muted); font: inherit; font-weight: 700; font-size: 14.5px; cursor: pointer; }
.gpd-tabs button:hover { color: var(--gpd-p); background: transparent; }
.gpd-tabs button.is-active { background: #fff; color: var(--gpd-p); box-shadow: 0 2px 8px rgba(42, 0, 73, .1); }
.gpd-section[hidden] { display: none; }
.gpd-upload { position: relative; display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 50px; border: 2px dashed #CDB4E8; border-radius: 14px; background: #FCF8FF; color: var(--gpd-p); font-weight: 700; cursor: pointer; transition: border-color .2s ease, background .2s ease; }
.gpd-upload:hover { border-color: var(--gpd-p); background: var(--gpd-soft); }
.gpd-upload input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.gpd-note { margin: 6px 2px 0; font-size: 12px; color: var(--gpd-muted); }
.gpd-controls[hidden] { display: none; }
.gpd-controls { display: grid; gap: 12px; margin-top: 12px; }
.gpd-range, .gpd-field { display: grid; gap: 4px; margin: 0; font-size: 13px; font-weight: 700; color: var(--gpd-ink); }
.gpd-range { grid-template-columns: 64px minmax(0, 1fr); align-items: center; }
.gpd-range input[type="range"] { width: 100%; height: 26px; margin: 0; accent-color: var(--gpd-p); }
.gpd-field textarea { width: 100%; min-height: 56px; padding: 10px 12px; border: 1.5px solid var(--gpd-line); border-radius: 12px; font: inherit; font-size: 16px; resize: vertical; box-sizing: border-box; background: #FCFBFE; }
.gpd-field textarea:focus { outline: none; border-color: var(--gpd-p); background: #fff; }
.gpd-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.gpd-chips button, .gpd-textchip { min-height: 38px; padding: 6px 14px; border: 1.5px solid var(--gpd-line); border-radius: 999px; background: #fff; color: var(--gpd-ink); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; }
.gpd-chips button:hover, .gpd-textchip:hover { border-color: var(--gpd-p); color: var(--gpd-p); background: #fff; }
.gpd-chips .is-danger { color: #C62828; }
.gpd-textlist { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.gpd-textlist:empty { display: none; }
.gpd-textchip.is-active, .gpd-textchip.is-active:hover { border-color: var(--gpd-p); background: var(--gpd-p); color: #fff; }
.gpd-fonts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.gpd-font { min-height: 42px; padding: 4px 6px; border: 1.5px solid var(--gpd-line); border-radius: 10px; background: #fff; color: var(--gpd-ink); font-size: 15px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gpd-font:hover { border-color: var(--gpd-p); background: #fff; color: var(--gpd-ink); }
.gpd-font.is-active, .gpd-font.is-active:hover { border-color: var(--gpd-p); background: var(--gpd-soft); color: var(--gpd-p); }
.gpd-colors { display: flex; flex-wrap: wrap; gap: 10px; }
.gpd-color, .gpd-color:hover { width: 32px; height: 32px; padding: 0; border: 0; border-radius: 50%; background: var(--c); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .15); cursor: pointer; outline: 2px solid transparent; outline-offset: 3px; }
.gpd-color.is-active { outline-color: var(--gpd-p); }

.gpd-btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 10px 24px; border: 2px solid transparent; border-radius: 999px; font: inherit; font-weight: 700; font-size: 14.5px; cursor: pointer; }
.gpd-btn--ghost, .gpd-btn--ghost:hover { background: #fff; border-color: var(--gpd-line); color: var(--gpd-ink); }
.gpd-btn--ghost:hover { border-color: var(--gpd-p); color: var(--gpd-p); }
.gpd-btn--block { width: 100%; }
.gpd-link, .gpd-link:hover { padding: 0; border: 0; background: none; color: var(--gpd-p); font: inherit; font-weight: 700; font-size: 13.5px; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.gpd-link--muted, .gpd-link--muted:hover { color: var(--gpd-muted); font-weight: 600; white-space: nowrap; }
.gpd-link--danger, .gpd-link--danger:hover { color: #C62828; }

.gpd-status { margin: 10px 2px 0; font-size: 13px; color: var(--gpd-muted); }
.gpd-status:empty { display: none; }
.gpd-status.is-saved { color: #1B8A4B; font-weight: 700; }
.gpd-card__error { margin: 8px 2px 0; color: #C62828; font-weight: 600; font-size: 14px; }

.gpd-saving { position: absolute; inset: 0; z-index: 5; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; border-radius: 20px; background: rgba(255, 255, 255, .88); font-weight: 700; color: var(--gpd-p); }
.gpd-saving[hidden] { display: none; }
.gpd-spinner { width: 40px; height: 40px; border: 4px solid var(--gpd-soft); border-top-color: var(--gpd-p); border-radius: 50%; animation: gpdSpin .8s linear infinite; }
@keyframes gpdSpin { to { transform: rotate(360deg); } }
.gpd-toast { position: absolute; left: 50%; bottom: 40px; z-index: 6; max-width: calc(100% - 24px); padding: 8px 16px; border-radius: 999px; background: var(--gpd-ink); color: #fff; font-size: 13.5px; font-weight: 600; text-align: center; transform: translate(-50%, 12px); opacity: 0; transition: all .25s ease; pointer-events: none; }
.gpd-toast.is-visible { transform: translate(-50%, 0); opacity: 1; }

/* Head actions: Preview + Start over */
.gpd-studio__actions { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.gpd-preview-btn, .gpd-preview-btn:hover { display: inline-flex; align-items: center; gap: 8px; min-height: 42px; padding: 8px 18px; border: 1.5px solid var(--gpd-p); border-radius: 999px; background: #fff; color: var(--gpd-p); font: inherit; font-weight: 700; font-size: 14px; cursor: pointer; transition: background .2s ease, color .2s ease; }
.gpd-preview-btn:hover { background: var(--gpd-p); color: #fff; }
.gpd-preview-btn--sm, .gpd-preview-btn--sm:hover { min-height: 36px; padding: 6px 14px; font-size: 13px; }
.gpd-studio__onleft { margin: -4px 0 12px; padding: 8px 12px; border-radius: 10px; background: var(--gpd-soft); color: var(--gpd-p); font-size: 13px; font-weight: 600; }
.gpd-studio__onleft[hidden] { display: none; }
/* When the design sits on the left, the head Preview button would be a duplicate. */
.gpd-has-left .gpd-studio__actions .gpd-preview-btn { display: none; }

/* Left column (desktop): live design + product photos switch */
.gpd-left { position: sticky; top: 88px; min-width: 0; }
body.admin-bar .gpd-left { top: 120px; }
.gpd-left__bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.gpd-left__switch { display: inline-flex; gap: 4px; padding: 4px; border-radius: 999px; background: var(--gpd-soft); }
.gpd-left__switch button, .gpd-left__switch button:hover { min-height: 38px; padding: 6px 18px; border: 0; border-radius: 999px; background: transparent; color: var(--gpd-muted); font: inherit; font-weight: 700; font-size: 14px; cursor: pointer; }
.gpd-left__switch button:hover { color: var(--gpd-p); }
.gpd-left__switch button.is-active { background: #fff; color: var(--gpd-p); box-shadow: 0 2px 8px rgba(42, 0, 73, .1); }
.gpd-left .gpd-stage { padding: 0; border-radius: var(--g-radius-lg, 24px); background: transparent; }
.gpd-left .gpd-canvas { border-radius: var(--g-radius-lg, 24px); box-shadow: none; }
.gpd-left .gpd-stage__hint { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; margin: 12px 0 0; padding: 10px 14px; border-radius: 12px; background: var(--gpd-soft); color: var(--gpd-p); font-size: 13px; font-weight: 600; box-sizing: border-box; }
.gpd-view-photos .gpd-left__slot { display: none; }
/* The sale badge would sit on top of the switch/design – show it only with the photos. */
.single-product div.product.gpd-view-design span.onsale { display: none; }
.single-product div.product.gpd-view-photos span.onsale { top: 78px; }
/* Keep the gallery measurable (flexslider) while hidden behind the design. */
.gpd-view-design .gpd-left .woocommerce-product-gallery { position: absolute !important; left: -10000px; top: 0; width: 600px !important; visibility: hidden; }
.woocommerce.single-product div.product .gpd-left div.images.woocommerce-product-gallery { top: 0; }

/* Preview lightbox */
.gpd-lightbox { position: fixed; inset: 0; z-index: 100000; display: none; align-items: center; justify-content: center; padding: 20px; background: rgba(20, 8, 32, .72); }
.gpd-lightbox.is-open { display: flex; }
.gpd-lightbox__box { display: flex; flex-direction: column; max-width: min(760px, 100%); max-height: 100%; border-radius: 20px; background: #fff; overflow: hidden; box-shadow: 0 30px 80px rgba(0, 0, 0, .35); }
.gpd-lightbox__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 12px 12px 20px; border-bottom: 1px solid var(--gpd-line); color: var(--gpd-ink); }
.gpd-lightbox__close, .gpd-lightbox__close:hover { display: grid; place-items: center; width: 40px; height: 40px; padding: 0; border: 0; border-radius: 50%; background: var(--gpd-soft); color: var(--gpd-p); font-size: 26px; line-height: 1; cursor: pointer; }
.gpd-lightbox img { display: block; width: auto; max-width: 100%; max-height: calc(100vh - 110px); margin: 0 auto; object-fit: contain; }
html.gpd-lock, html.gpd-lock body { overflow: hidden; }

/* Text style + size */
.gpd-styles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.gpd-styles button, .gpd-styles button:hover { min-height: 40px; padding: 4px 8px; border: 1.5px solid var(--gpd-line); border-radius: 10px; background: #fff; color: var(--gpd-ink); font-family: inherit; font-size: 14px; cursor: pointer; }
.gpd-styles button:hover { border-color: var(--gpd-p); }
.gpd-styles button.is-active, .gpd-styles button.is-active:hover { border-color: var(--gpd-p); background: var(--gpd-soft); color: var(--gpd-p); }
.gpd-size__row { display: flex; align-items: center; gap: 8px; }
.gpd-size__row input[type=range] { flex: 1; min-width: 0; }
.gpd-size__btn, .gpd-size__btn:hover { flex: 0 0 38px; height: 38px; padding: 0; border: 1.5px solid var(--gpd-line); border-radius: 10px; background: #fff; color: var(--gpd-p); font: inherit; font-weight: 800; font-size: 13px; cursor: pointer; }
.gpd-size__btn:hover { border-color: var(--gpd-p); background: var(--gpd-soft); }
.gpd-size__val { flex: 0 0 34px; text-align: right; color: var(--gpd-p); font-weight: 800; font-size: 13px; }

/* Phones: head stacks – title row, then Preview / Start over on their own row. */
@media (max-width: 600px) {
	.gpd-studio__head { flex-wrap: wrap; gap: 10px 12px; }
	.gpd-studio__icon { flex-basis: 38px; width: 38px; height: 38px; }
	.gpd-studio__titles { flex: 1 1 calc(100% - 50px); }
	.gpd-studio__title { font-size: 16px; }
	.gpd-studio__sub { font-size: 12.5px; }
	.gpd-studio__actions { flex: 1 1 100%; justify-content: space-between; padding-top: 10px; border-top: 1px solid var(--gpd-line); }
	.gpd-studio__actions .gpd-preview-btn { flex: 1; justify-content: center; }
}

/* Phones/tablets: the design lives inside the studio; the desktop left bar is never shown. */
@media (max-width: 900px) {
	.gpd-left { position: static; }
	.gpd-left__bar, .gpd-left__slot { display: none !important; }
	.gpd-left .woocommerce-product-gallery { position: relative !important; left: 0 !important; width: 100% !important; visibility: visible !important; }
	.single-product div.product span.onsale { display: flex !important; top: 16px !important; }
}

/* Cart / order */
.gpd-cart-design { display: inline-flex; align-items: center; gap: 10px; vertical-align: middle; }
.gpd-cart-design__name { font-weight: 600; line-height: 1.3; text-align: left; }
.gpd-cart-design img, .gpd-order-design img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; border: 1px solid var(--g-line, #ECE6F2); }
.gpd-order-design { margin-top: 8px; }
.gpd-order-design img { width: 96px; height: 96px; }

@media (max-width: 767px) {
	.gpd-studio { padding: 12px; border-radius: 18px; }
	.gpd-fonts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
	.gpd-stage { padding: 6px; }
}
@media (prefers-reduced-motion: reduce) { .gpd-spinner { animation-duration: 2s; } }
