/**
 * TP Woocommerce Product Gift - עיצוב צד לקוח.
 *
 * נכתב עם מאפיינים לוגיים (inline-start/end) כדי לעבוד גם ב-RTL וגם ב-LTR.
 *
 * מבנה הקובץ:
 *   1. בסיס - הסגנון "כרטיסים" (cards), שהוא גם ברירת המחדל
 *   2. וריאציות הסגנון: compact / list / minimal / strip
 *   3. שורות מתנה בטבלת העגלה
 *   4. בלוק המתנות בעמוד התודה
 *
 * כל הסגנונות עובדים על אותו HTML בדיוק - רק CSS משתנה. לכן התצוגה
 * המקדימה במסך הניהול מדויקת ב-100%.
 */

.tpwpg-sections {
	margin: 0 0 2em;
}

/* ================================================================
 * 1. בסיס / סגנון "כרטיסים"
 * ============================================================= */

.tpwpg-section {
	position: relative;
	background: #fff;
	border: 1px solid #e5e7eb;
	border-radius: 14px;
	padding: 1.5em;
	margin: 0 0 1.25em;
	box-shadow: 0 1px 2px rgba( 16, 24, 40, 0.04 );
}

.tpwpg-section.is-eligible {
	border-color: #bbf7d0;
	background: linear-gradient( 180deg, #f6fef8 0%, #fff 60% );
}

.tpwpg-section.is-loading {
	pointer-events: none;
}

.tpwpg-section__head {
	display: flex;
	align-items: center;
	gap: 0.9em;
	margin-bottom: 1.1em;
}

.tpwpg-section__icon {
	flex: 0 0 auto;
	display: grid;
	place-items: center;
	width: 46px;
	height: 46px;
	border-radius: 12px;
	background: #ecfdf3;
	font-size: 22px;
	line-height: 1;
}

.tpwpg-section.is-locked .tpwpg-section__icon {
	background: #f3f4f6;
	filter: grayscale( 1 );
}

.tpwpg-section__titles {
	flex: 1 1 auto;
	min-width: 0;
}

.tpwpg-section__title {
	margin: 0;
	font-size: 1.15em;
	line-height: 1.3;
	font-weight: 700;
	color: #111827;
}

.tpwpg-section__subtitle {
	margin: 0.25em 0 0;
	font-size: 0.9em;
	color: #6b7280;
}

.tpwpg-section__counter {
	flex: 0 0 auto;
	font-size: 0.82em;
	font-weight: 600;
	color: #047857;
	background: #ecfdf3;
	border: 1px solid #a7f3d0;
	border-radius: 999px;
	padding: 0.35em 0.85em;
	white-space: nowrap;
}

/* ------------------------------------------------------------ התקדמות */

.tpwpg-progress {
	margin: 0 0 1.25em;
}

.tpwpg-progress__track {
	height: 8px;
	border-radius: 999px;
	background: #f1f5f9;
	overflow: hidden;
}

.tpwpg-progress__bar {
	height: 100%;
	border-radius: 999px;
	background: linear-gradient( 90deg, #34d399, #10b981 );
	transition: width 0.4s ease;
}

.tpwpg-progress__label {
	margin: 0.6em 0 0;
	font-size: 0.92em;
	font-weight: 600;
	color: #b45309;
}

/* --------------------------------------------------------------- כרטיס */

.tpwpg-grid {
	display: grid;
	grid-template-columns: repeat( auto-fill, minmax( 180px, 1fr ) );
	gap: 1em;
}

.tpwpg-section--cards.is-auto .tpwpg-grid,
.tpwpg-section--compact.is-auto .tpwpg-grid {
	grid-template-columns: minmax( 0, 320px );
}

.tpwpg-gift-card {
	display: flex;
	flex-direction: column;
	background: #fff;
	border: 1px solid #e5e7eb;
	border-radius: 12px;
	overflow: hidden;
	transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.tpwpg-gift-card:hover {
	border-color: #cbd5e1;
	box-shadow: 0 6px 18px rgba( 16, 24, 40, 0.08 );
	transform: translateY( -2px );
}

.tpwpg-gift-card.is-selected {
	border-color: #10b981;
	box-shadow: 0 0 0 2px rgba( 16, 185, 129, 0.18 );
}

.tpwpg-gift-card.is-disabled {
	opacity: 0.55;
}

.tpwpg-gift-card.is-disabled:hover {
	transform: none;
	box-shadow: none;
}

.tpwpg-gift-card__media {
	position: relative;
	aspect-ratio: 1 / 1;
	background: #f8fafc;
}

.tpwpg-gift-card__media img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

.tpwpg-gift-card__check {
	position: absolute;
	inset-block-start: 8px;
	inset-inline-end: 8px;
	display: grid;
	place-items: center;
	width: 26px;
	height: 26px;
	border-radius: 50%;
	background: #10b981;
	color: #fff;
	font-size: 15px;
	font-weight: 700;
	line-height: 1;
	box-shadow: 0 2px 6px rgba( 16, 185, 129, 0.4 );
}

.tpwpg-gift-card__body {
	flex: 1 1 auto;
	padding: 0.85em 0.9em 0.6em;
}

.tpwpg-gift-card__name {
	margin: 0;
	font-size: 0.98em;
	font-weight: 600;
	line-height: 1.35;
	color: #111827;
}

.tpwpg-gift-card__desc {
	margin: 0.35em 0 0;
	font-size: 0.85em;
	line-height: 1.4;
	color: #6b7280;
}

/*
 * התיאור מוצג בכל הסגנונות. בסגנונות הצפופים הוא רק קטן יותר ונחתך אחרי
 * מספר שורות - אף פעם לא מוסתר. תיאור שהמנהל הקליד ולא מופיע בשום מקום
 * הוא באג מבחינת המשתמש, לא "עיצוב קומפקטי"; מי שלא רוצה תיאור פשוט
 * משאיר את השדה ריק.
 */
.tpwpg-gift-card__desc {
	display: -webkit-box;
	-webkit-line-clamp: 3;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

.tpwpg-gift-card__stock {
	margin: 0.5em 0 0;
	font-size: 0.8em;
	font-weight: 600;
	color: #b91c1c;
}

.tpwpg-gift-card__footer {
	padding: 0 0.9em 0.9em;
}

.tpwpg-gift-card__badge {
	display: inline-block;
	font-size: 0.82em;
	font-weight: 600;
	color: #047857;
	background: #ecfdf3;
	border-radius: 999px;
	padding: 0.35em 0.8em;
}

/* --------------------------------------------------------------- כפתור */

.tpwpg-gift-btn {
	display: block;
	width: 100%;
	border: 1px solid transparent;
	border-radius: 9px;
	padding: 0.62em 0.9em;
	font-size: 0.9em;
	font-weight: 600;
	line-height: 1.2;
	cursor: pointer;
	transition: background-color 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}

.tpwpg-gift-btn--select {
	background: #10b981;
	color: #fff;
}

.tpwpg-gift-btn--select:hover:not( :disabled ) {
	background: #059669;
}

.tpwpg-gift-btn--remove {
	background: #fff;
	border-color: #e5e7eb;
	color: #6b7280;
}

.tpwpg-gift-btn--remove:hover:not( :disabled ) {
	border-color: #fca5a5;
	color: #b91c1c;
}

.tpwpg-gift-btn:disabled {
	cursor: not-allowed;
	opacity: 0.6;
}

/* -------------------------------------------------------------- טעינה */

.tpwpg-section__overlay {
	position: absolute;
	inset: 0;
	display: none;
	place-items: center;
	background: rgba( 255, 255, 255, 0.65 );
	border-radius: 14px;
	z-index: 2;
}

.tpwpg-section.is-loading .tpwpg-section__overlay {
	display: grid;
}

.tpwpg-spinner {
	width: 30px;
	height: 30px;
	border-radius: 50%;
	border: 3px solid #d1fae5;
	border-top-color: #10b981;
	animation: tpwpg-spin 0.7s linear infinite;
}

@keyframes tpwpg-spin {
	to {
		transform: rotate( 360deg );
	}
}

@media ( prefers-reduced-motion: reduce ) {
	.tpwpg-gift-card,
	.tpwpg-progress__bar,
	.tpwpg-toast {
		transition: none;
	}

	.tpwpg-spinner {
		animation-duration: 2s;
	}
}

/* ================================================================
 * 2. וריאציות סגנון
 * ============================================================= */

/* ------------------------------------------- compact: כרטיסים קטנים */

.tpwpg-section--compact {
	padding: 1.1em 1.2em;
	border-radius: 12px;
}

.tpwpg-section--compact .tpwpg-section__head {
	gap: 0.7em;
	margin-bottom: 0.85em;
}

.tpwpg-section--compact .tpwpg-section__icon {
	width: 36px;
	height: 36px;
	font-size: 18px;
	border-radius: 10px;
}

.tpwpg-section--compact .tpwpg-section__title {
	font-size: 1em;
}

.tpwpg-section--compact .tpwpg-section__subtitle {
	font-size: 0.82em;
}

.tpwpg-section--compact .tpwpg-grid {
	grid-template-columns: repeat( auto-fill, minmax( 120px, 1fr ) );
	gap: 0.7em;
}

.tpwpg-section--compact .tpwpg-gift-card__body {
	padding: 0.55em 0.6em 0.3em;
}

.tpwpg-section--compact .tpwpg-gift-card__name {
	font-size: 0.85em;
}

.tpwpg-section--compact .tpwpg-gift-card__desc {
	margin-top: 0.2em;
	font-size: 0.76em;
	line-height: 1.35;
	-webkit-line-clamp: 2;
}

.tpwpg-section--compact .tpwpg-gift-card__footer {
	padding: 0 0.6em 0.6em;
}

.tpwpg-section--compact .tpwpg-gift-btn {
	font-size: 0.8em;
	padding: 0.45em 0.6em;
	border-radius: 7px;
}

/* -------------------------------------------------- list: רשימה */

.tpwpg-section--list .tpwpg-grid {
	grid-template-columns: minmax( 0, 1fr );
	gap: 0.5em;
}

.tpwpg-section--list .tpwpg-gift-card {
	flex-direction: row;
	align-items: center;
	gap: 0.9em;
	padding: 0.6em 0.7em;
	border-radius: 10px;
}

.tpwpg-section--list .tpwpg-gift-card:hover {
	transform: none;
	box-shadow: none;
}

.tpwpg-section--list .tpwpg-gift-card__media {
	flex: 0 0 56px;
	width: 56px;
	height: 56px;
	aspect-ratio: auto;
	border-radius: 8px;
	overflow: hidden;
}

.tpwpg-section--list .tpwpg-gift-card__check {
	width: 20px;
	height: 20px;
	font-size: 12px;
	inset-block-start: 3px;
	inset-inline-end: 3px;
}

.tpwpg-section--list .tpwpg-gift-card__body {
	padding: 0;
}

.tpwpg-section--list .tpwpg-gift-card__name {
	font-size: 0.92em;
}

.tpwpg-section--list .tpwpg-gift-card__desc {
	margin-top: 0.15em;
	font-size: 0.8em;
}

.tpwpg-section--list .tpwpg-gift-card__footer {
	flex: 0 0 auto;
	padding: 0;
}

.tpwpg-section--list .tpwpg-gift-btn {
	width: auto;
	white-space: nowrap;
	padding: 0.5em 1.1em;
	font-size: 0.85em;
}

/* ------------------------------------------------ minimal: עדין */

.tpwpg-section--minimal,
.tpwpg-section--minimal.is-eligible {
	background: none;
	border: 0;
	border-radius: 0;
	box-shadow: none;
	padding: 0.4em 0;
	margin-bottom: 1em;
}

.tpwpg-section--minimal .tpwpg-section__icon {
	display: none;
}

.tpwpg-section--minimal .tpwpg-section__head {
	gap: 0.5em;
	margin-bottom: 0.5em;
}

.tpwpg-section--minimal .tpwpg-section__title {
	font-size: 0.95em;
	font-weight: 600;
}

.tpwpg-section--minimal .tpwpg-section__subtitle {
	font-size: 0.82em;
}

.tpwpg-section--minimal .tpwpg-section__counter {
	font-size: 0.75em;
	padding: 0.2em 0.6em;
}

.tpwpg-section--minimal .tpwpg-progress {
	margin-bottom: 0.75em;
}

.tpwpg-section--minimal .tpwpg-progress__track {
	height: 5px;
}

.tpwpg-section--minimal .tpwpg-progress__label {
	font-size: 0.84em;
	font-weight: 500;
}

.tpwpg-section--minimal .tpwpg-grid {
	grid-template-columns: minmax( 0, 1fr );
	gap: 0;
}

.tpwpg-section--minimal .tpwpg-gift-card,
.tpwpg-section--minimal .tpwpg-gift-card:hover,
.tpwpg-section--minimal .tpwpg-gift-card.is-selected {
	flex-direction: row;
	align-items: center;
	gap: 0.7em;
	background: none;
	border: 0;
	border-radius: 0;
	box-shadow: none;
	transform: none;
	padding: 0.5em 0;
	overflow: visible;
}

.tpwpg-section--minimal .tpwpg-gift-card + .tpwpg-gift-card {
	border-top: 1px solid #f1f5f9;
}

.tpwpg-section--minimal .tpwpg-gift-card__media {
	position: relative;
	flex: 0 0 40px;
	width: 40px;
	height: 40px;
	aspect-ratio: auto;
	border-radius: 50%;
	overflow: visible;
	background: none;
}

.tpwpg-section--minimal .tpwpg-gift-card__media img {
	border-radius: 50%;
}

.tpwpg-section--minimal .tpwpg-gift-card__check {
	width: 17px;
	height: 17px;
	font-size: 10px;
	inset-block-start: -3px;
	inset-inline-end: -3px;
	box-shadow: 0 0 0 2px #fff;
}

.tpwpg-section--minimal .tpwpg-gift-card__body {
	padding: 0;
}

.tpwpg-section--minimal .tpwpg-gift-card__name {
	font-size: 0.88em;
	font-weight: 500;
}

.tpwpg-section--minimal .tpwpg-gift-card__desc {
	margin-top: 0.1em;
	font-size: 0.78em;
	line-height: 1.3;
	-webkit-line-clamp: 1;
}

.tpwpg-section--minimal .tpwpg-gift-card__stock {
	font-size: 0.75em;
	font-weight: 500;
}

.tpwpg-section--minimal .tpwpg-gift-card__footer {
	flex: 0 0 auto;
	padding: 0;
}

.tpwpg-section--minimal .tpwpg-gift-btn {
	width: auto;
	background: none;
	border: 0;
	padding: 0.2em 0.3em;
	font-size: 0.85em;
	font-weight: 600;
	text-decoration: underline;
	text-underline-offset: 3px;
	color: #047857;
}

.tpwpg-section--minimal .tpwpg-gift-btn--remove {
	color: #9ca3af;
	font-weight: 500;
}

.tpwpg-section--minimal .tpwpg-gift-btn--remove:hover:not( :disabled ) {
	color: #b91c1c;
}

.tpwpg-section--minimal .tpwpg-section__overlay {
	border-radius: 6px;
}

/* --------------------------------------------------- strip: רצועה */

.tpwpg-section--strip {
	padding: 1em 1.2em;
	border-radius: 12px;
}

.tpwpg-section--strip .tpwpg-section__head {
	margin-bottom: 0.8em;
}

.tpwpg-section--strip .tpwpg-section__icon {
	width: 38px;
	height: 38px;
	font-size: 19px;
	border-radius: 10px;
}

.tpwpg-section--strip .tpwpg-section__title {
	font-size: 1em;
}

.tpwpg-section--strip .tpwpg-grid {
	display: flex;
	gap: 0.6em;
	overflow-x: auto;
	padding-bottom: 0.5em;
	scroll-snap-type: x proximity;
	scrollbar-width: thin;
}

.tpwpg-section--strip .tpwpg-grid::-webkit-scrollbar {
	height: 6px;
}

.tpwpg-section--strip .tpwpg-grid::-webkit-scrollbar-thumb {
	background: #d1d5db;
	border-radius: 999px;
}

.tpwpg-section--strip .tpwpg-gift-card {
	flex: 0 0 120px;
	scroll-snap-align: start;
}

.tpwpg-section--strip .tpwpg-gift-card:hover {
	transform: none;
}

.tpwpg-section--strip .tpwpg-gift-card__body {
	padding: 0.5em 0.55em 0.25em;
}

.tpwpg-section--strip .tpwpg-gift-card__name {
	font-size: 0.8em;
	line-height: 1.3;
}

.tpwpg-section--strip .tpwpg-gift-card__desc {
	margin-top: 0.15em;
	font-size: 0.72em;
	line-height: 1.3;
	-webkit-line-clamp: 2;
}

.tpwpg-section--strip .tpwpg-gift-card__stock {
	font-size: 0.72em;
}

.tpwpg-section--strip .tpwpg-gift-card__footer {
	padding: 0 0.55em 0.55em;
}

.tpwpg-section--strip .tpwpg-gift-btn {
	font-size: 0.75em;
	padding: 0.4em 0.5em;
	border-radius: 7px;
}

/* ================================================================
 * 2.5 קרוסלת מובייל
 *
 * במסך צר הרשת הופכת לרצועה נגללת שמציגה מתנה אחת ועוד חצי מהבאה - ההצצה
 * החלקית עצמה היא הסימן שיש עוד מה לבחור - ולצידה חצים לשני הכיוונים.
 * החצים מודפסים תמיד ב-HTML ומוסתרים בדסקטופ, כדי שהם ישרדו כל החלפת
 * HTML של ווקומרס בלי אתחול מחדש ב-JavaScript.
 * ============================================================= */

.tpwpg-carousel {
	position: relative;
}

/* בדסקטופ אין קרוסלה בכלל - הרשת נשארת רשת. */
.tpwpg-carousel__nav {
	display: none;
}

@media ( max-width: 767px ) {

	.tpwpg-section.has-carousel .tpwpg-grid {
		display: flex;
		gap: 0.7em;
		overflow-x: auto;
		scroll-snap-type: x mandatory;
		scroll-behavior: smooth;
		-webkit-overflow-scrolling: touch;
		scrollbar-width: none;
		/*
		 * ריפוד + מרג'ין שלילי: בלעדיהם צל הכרטיס הנבחר (box-shadow)
		 * נחתך על ידי ה-overflow של המכל.
		 */
		padding: 4px 4px 0.5em;
		margin: -4px -4px 0;
	}

	.tpwpg-section.has-carousel .tpwpg-grid::-webkit-scrollbar {
		display: none;
	}

	/*
	 * 66% = מתנה אחת מלאה ועוד כחצי מהבאה. הכרטיס לא מתכווץ ולא נמתח,
	 * כך שהיחס נשמר גם בשתי מתנות וגם בעשר.
	 */
	.tpwpg-section.has-carousel .tpwpg-gift-card {
		flex: 0 0 66%;
		scroll-snap-align: start;
	}

	/* בסגנונות השורה הכרטיס רחב מטבעו, ולכן ההצצה קטנה יותר. */
	.tpwpg-section--list.has-carousel .tpwpg-gift-card,
	.tpwpg-section--minimal.has-carousel .tpwpg-gift-card {
		flex: 0 0 84%;
	}

	/* ברצועה אופקית הקו המפריד בין השורות כבר לא רלוונטי. */
	.tpwpg-section--minimal.has-carousel .tpwpg-gift-card + .tpwpg-gift-card {
		border-top: 0;
	}

	/* ---------------------------------------------------------- חצים */

	.tpwpg-section.has-carousel .tpwpg-carousel__nav {
		display: grid;
		place-items: center;
		position: absolute;
		inset-block-start: 50%;
		transform: translateY( -50% );
		z-index: 2;
		width: 34px;
		height: 34px;
		padding: 0;
		border: 1px solid #e5e7eb;
		border-radius: 50%;
		background: #fff;
		color: #111827;
		box-shadow: 0 2px 8px rgba( 16, 24, 40, 0.16 );
		cursor: pointer;
		transition: opacity 0.2s ease;
	}

	.tpwpg-section.has-carousel .tpwpg-carousel__nav--prev {
		inset-inline-start: 2px;
	}

	.tpwpg-section.has-carousel .tpwpg-carousel__nav--next {
		inset-inline-end: 2px;
	}

	.tpwpg-carousel__nav svg {
		width: 17px;
		height: 17px;
		fill: none;
		stroke: currentColor;
		stroke-width: 2.2;
		stroke-linecap: round;
		stroke-linejoin: round;
	}

	/* ה-path מצייר חץ שמאלה: "הבא" הוא אותו חץ מסובב, ו-RTL הופך את שניהם. */
	.tpwpg-carousel__nav--next svg,
	[dir='rtl'] .tpwpg-carousel__nav--prev svg,
	.rtl .tpwpg-carousel__nav--prev svg {
		transform: rotate( 180deg );
	}

	[dir='rtl'] .tpwpg-carousel__nav--next svg,
	.rtl .tpwpg-carousel__nav--next svg {
		transform: none;
	}

	.tpwpg-section.has-carousel .tpwpg-carousel__nav:disabled {
		opacity: 0;
		pointer-events: none;
	}

	/* בסקשן שעדיין לא זכאי הכרטיסים מעומעמים - גם החצים. */
	.tpwpg-section.is-locked.has-carousel .tpwpg-carousel__nav {
		opacity: 0.55;
	}
}

@media ( prefers-reduced-motion: reduce ) {
	.tpwpg-section.has-carousel .tpwpg-grid {
		scroll-behavior: auto;
	}

	.tpwpg-carousel__nav {
		transition: none;
	}
}

/* --------------------------------------------------------------- הודעה */

.tpwpg-toast {
	position: fixed;
	inset-block-end: 24px;
	inset-inline-start: 24px;
	z-index: 999999;
	max-width: min( 360px, calc( 100vw - 48px ) );
	padding: 0.9em 1.1em;
	border-radius: 10px;
	font-size: 0.92em;
	font-weight: 600;
	line-height: 1.4;
	color: #fff;
	background: #111827;
	box-shadow: 0 10px 30px rgba( 16, 24, 40, 0.22 );
	opacity: 0;
	transform: translateY( 12px );
	transition: opacity 0.25s ease, transform 0.25s ease;
}

.tpwpg-toast.is-visible {
	opacity: 1;
	transform: translateY( 0 );
}

.tpwpg-toast--success {
	background: #047857;
}

.tpwpg-toast--error {
	background: #b91c1c;
}

/* ================================================================
 * 3. שורות מתנה בטבלת העגלה
 * ============================================================= */

.tpwpg-cart-badge {
	display: inline-block;
	margin-inline-start: 0.4em;
	padding: 0.15em 0.55em;
	border-radius: 999px;
	background: #ecfdf3;
	color: #047857;
	font-size: 0.78em;
	font-weight: 700;
	white-space: nowrap;
}

.tpwpg-cart-free {
	font-weight: 700;
	color: #047857;
}

.woocommerce-cart-form .tpwpg-cart-gift-row,
.woocommerce-cart-form .tpwpg-cart-gift-row > td {
	background: #f8fefa;
}

.tpwpg-cart-gift-row--external .product-thumbnail img {
	max-width: 100%;
	height: auto;
	border-radius: 4px;
}

.tpwpg-cart-gift-row .tpwpg-cart-qty {
	font-weight: 600;
}

/* ================================================================
 * 4. מתנות בעמוד תודה / צפייה בהזמנה
 * ============================================================= */

.tpwpg-order-gifts {
	margin: 2em 0;
	padding: 1.25em 1.4em;
	background: #f6fef8;
	border: 1px solid #bbf7d0;
	border-radius: 12px;
}

.tpwpg-order-gifts__title {
	display: flex;
	align-items: center;
	gap: 0.5em;
	margin: 0 0 0.9em;
	font-size: 1.1em;
	color: #065f46;
}

.tpwpg-order-gifts__list {
	list-style: none;
	margin: 0;
	padding: 0;
	display: grid;
	gap: 0.75em;
}

.tpwpg-order-gifts__item {
	display: flex;
	align-items: center;
	gap: 0.9em;
}

.tpwpg-order-gifts__image {
	width: 64px;
	height: 64px;
	object-fit: cover;
	border-radius: 8px;
	flex: 0 0 auto;
}

.tpwpg-order-gifts__body {
	display: flex;
	flex-direction: column;
}

.tpwpg-order-gifts__name {
	font-weight: 600;
	color: #111827;
}

.tpwpg-order-gifts__campaign {
	font-size: 0.85em;
	color: #6b7280;
}

.tpwpg-order-gifts__note {
	margin: 1em 0 0;
	font-size: 0.88em;
	color: #4b5563;
}
