/* Scoped Local Reset for TKH Flip Cards */
:where(.tkh-flip-wrap, .tkh-flip-wrap *) {
	box-sizing: border-box;
}
:where(.tkh-flip-wrap) h1,
:where(.tkh-flip-wrap) h2,
:where(.tkh-flip-wrap) h3,
:where(.tkh-flip-wrap) h4,
:where(.tkh-flip-wrap) p,
:where(.tkh-flip-wrap) ul,
:where(.tkh-flip-wrap) ol,
:where(.tkh-flip-wrap) li {
	margin: 0;
	padding: 0;
}
:where(.tkh-flip-wrap) a {
	color: inherit;
	text-decoration: none;
}
:where(.tkh-flip-wrap) button {
	background: none;
	border: none;
	padding: 0;
	font: inherit;
	color: inherit;
	cursor: pointer;
}

/**
 * TKH Flip Cards - Frontend & Editor Stylesheet
 * Scoped to .tkh-flip-wrap and .khalaf-{{ID}}
 *
 * @package Khalaf_Elementor_Widgets
 */

/* ==========================================================================
   1. Root Variables & Section Layout
   ========================================================================== */

.tkh-flip-wrap {
	--tkh-flip-navy: #292f6e;
	--tkh-flip-navy-d: #171b45;
	--tkh-flip-teal: #5bc4c4;
	--tkh-flip-teal-d: #2a9d9d;
	--tkh-flip-gold: #d4b06a;
	--tkh-flip-mint: #eaf7f6;
	--tkh-flip-paper: #f3f5fb;
	--tkh-flip-white: #ffffff;
	--tkh-flip-font-display: "Bricolage Grotesque", "Bricolage Fallback", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
	--tkh-flip-font-body: "Manrope", "Manrope Fallback", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
	--tkh-flip-font-mono: "DM Mono", "DM Mono Fallback", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

	box-sizing: border-box;
	position: relative;
	width: 100%;
	background-color: transparent;
	margin-left: auto;
	margin-right: auto;
	padding: 10px 0;
}

.tkh-flip-wrap *,
.tkh-flip-wrap *::before,
.tkh-flip-wrap *::after {
	box-sizing: border-box;
}

/* ==========================================================================
   2. Flip Grid & 3D Stage
   ========================================================================== */

.tkh-flip-grid {
	display: grid;
	grid-template-columns: repeat(var(--tkh-flip-cols, var(--tkh-cols-fallback, 5)), 1fr);
	gap: var(--tkh-flip-gap, var(--tkh-gap-fallback, 14px));
	perspective: var(--tkh-flip-perspective, 1400px);
	list-style: none;
	margin: 0;
	padding: 0;
	position: relative;
	width: 100%;
}

/* ==========================================================================
   3. Flip Card Element & Preserved 3D Inner
   ========================================================================== */

.tkh-flip-card {
	position: relative;
	height: var(--tkh-card-height, var(--tkh-height-fallback, 340px));
	cursor: pointer;
	outline: none;
	border-radius: var(--tkh-card-radius, 30px);
	transition: transform 0.3s ease, box-shadow 0.3s ease;
	user-select: none;
	-webkit-tap-highlight-color: transparent;

	/* Default Presets for 5 Cards */
	--tkh-card-bg-front-preset: #292f6e;
	--tkh-card-color-front-preset: #ffffff;
	--tkh-card-title-color-front-preset: #ffffff;
	--tkh-card-border-front-preset: none;
}

.tkh-flip-card:focus-visible {
	outline: 3px solid var(--tkh-flip-teal);
	outline-offset: 4px;
}

/* Hover pre-lift before flip on fine pointers */
@media (hover: hover) and (pointer: fine) {
	.tkh-flip-card:hover {
		transform: translateY(-4px);
	}
}

.tkh-flip-inner {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	transform-style: preserve-3d;
	-webkit-transform-style: preserve-3d;
	transition: transform var(--tkh-flip-duration, 0.85s) var(--tkh-flip-easing, cubic-bezier(0.3, 1.2, 0.4, 1));
	border-radius: inherit;
}

/* 3D Transformations */
/* Axis: Y (Default) */
.tkh-flip-card.tkh-axis-y.is-flipped .tkh-flip-inner,
.tkh-flip-wrap.preview-back .tkh-flip-card.tkh-axis-y .tkh-flip-inner {
	transform: rotateY(var(--tkh-flip-angle-y, 180deg));
}

@media (hover: hover) and (pointer: fine) {
	.tkh-flip-card.tkh-trigger-hover.tkh-axis-y:hover .tkh-flip-inner,
	.tkh-flip-card.tkh-trigger-hover-click.tkh-axis-y:hover .tkh-flip-inner {
		transform: rotateY(var(--tkh-flip-angle-y, 180deg));
	}
}

/* Axis: X */
.tkh-flip-card.tkh-axis-x.is-flipped .tkh-flip-inner,
.tkh-flip-wrap.preview-back .tkh-flip-card.tkh-axis-x .tkh-flip-inner {
	transform: rotateX(var(--tkh-flip-angle-x, 180deg));
}

@media (hover: hover) and (pointer: fine) {
	.tkh-flip-card.tkh-trigger-hover.tkh-axis-x:hover .tkh-flip-inner,
	.tkh-flip-card.tkh-trigger-hover-click.tkh-axis-x:hover .tkh-flip-inner {
		transform: rotateX(var(--tkh-flip-angle-x, 180deg));
	}
}

/* Axis: Diagonal */
.tkh-flip-card.tkh-axis-diagonal.is-flipped .tkh-flip-inner,
.tkh-flip-wrap.preview-back .tkh-flip-card.tkh-axis-diagonal .tkh-flip-inner {
	transform: rotate3d(1, 1, 0, 180deg);
}

@media (hover: hover) and (pointer: fine) {
	.tkh-flip-card.tkh-trigger-hover.tkh-axis-diagonal:hover .tkh-flip-inner,
	.tkh-flip-card.tkh-trigger-hover-click.tkh-axis-diagonal:hover .tkh-flip-inner {
		transform: rotate3d(1, 1, 0, 180deg);
	}
}

/* Focus-only trigger */
.tkh-flip-card.tkh-trigger-focus:focus-within .tkh-flip-inner {
	transform: rotateY(180deg);
}

/* ==========================================================================
   4. Card Faces (Front & Back)
   ========================================================================== */

.tkh-flip-face {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	border-radius: inherit;
	padding: clamp(20px, 2.4vw, 26px) clamp(16px, 2vw, 22px);
	backface-visibility: hidden;
	-webkit-backface-visibility: hidden;
	transform-style: flat;
	display: flex;
	flex-direction: column;
	justify-content: space-between;
	overflow: hidden;
	box-shadow: 0 4px 20px rgba(41, 47, 110, 0.06);
	transition: box-shadow 0.4s ease, border-color 0.4s ease;
}

/* Front Face */
.tkh-flip-front {
	background-color: var(--tkh-front-bg, var(--tkh-card-bg-front-preset, #292f6e));
	color: var(--tkh-front-color, var(--tkh-card-color-front-preset, #ffffff));
	border: var(--tkh-front-border, var(--tkh-card-border-front-preset, none));
	transform: rotateY(0deg);
	-webkit-transform: rotateY(0deg);
	z-index: 3;
}

/* Back Face */
.tkh-flip-back {
	background-color: var(--tkh-back-bg, #ffffff);
	color: var(--tkh-back-color, #171b45);
	border: var(--tkh-back-border, none);
	transform: rotateY(180deg) translateZ(1px);
	-webkit-transform: rotateY(180deg) translateZ(1px);
	justify-content: center;
	z-index: 2;
}

.tkh-flip-card.tkh-axis-x .tkh-flip-back {
	transform: rotateX(180deg) translateZ(1px);
	-webkit-transform: rotateX(180deg) translateZ(1px);
}

.tkh-flip-card.tkh-axis-diagonal .tkh-flip-back {
	transform: rotate3d(1, 1, 0, 180deg) translateZ(1px);
	-webkit-transform: rotate3d(1, 1, 0, 180deg) translateZ(1px);
}

/* Default 5 Cards Color Presets */
.tkh-flip-grid > .tkh-flip-card:nth-child(5n+1) {
	--tkh-card-bg-front-preset: #292f6e;
	--tkh-card-color-front-preset: #ffffff;
	--tkh-card-title-color-front-preset: #ffffff;
}

.tkh-flip-grid > .tkh-flip-card:nth-child(5n+2) {
	--tkh-card-bg-front-preset: #5bc4c4;
	--tkh-card-color-front-preset: #171b45;
	--tkh-card-title-color-front-preset: #171b45;
}

.tkh-flip-grid > .tkh-flip-card:nth-child(5n+3) {
	--tkh-card-bg-front-preset: #d4b06a;
	--tkh-card-color-front-preset: #171b45;
	--tkh-card-title-color-front-preset: #171b45;
}

.tkh-flip-grid > .tkh-flip-card:nth-child(5n+4) {
	--tkh-card-bg-front-preset: #eaf7f6;
	--tkh-card-color-front-preset: #292f6e;
	--tkh-card-title-color-front-preset: #292f6e;
}

.tkh-flip-grid > .tkh-flip-card:nth-child(5n+5) {
	--tkh-card-bg-front-preset: #ffffff;
	--tkh-card-color-front-preset: #292f6e;
	--tkh-card-title-color-front-preset: #292f6e;
	--tkh-card-border-front-preset: 2px solid #292f6e;
}

/* ==========================================================================
   5. Content Elements (Front)
   ========================================================================== */

.tkh-flip-front-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	width: 100%;
}

.tkh-flip-num {
	font-family: var(--tkh-flip-font-mono);
	font-size: 13px;
	font-weight: 500;
	opacity: 0.7;
	letter-spacing: 1px;
	color: inherit;
}

.tkh-flip-eyebrow {
	font-family: var(--tkh-flip-font-mono);
	font-size: 12px;
	letter-spacing: 1.5px;
	text-transform: uppercase;
	color: inherit;
	opacity: 0.85;
}

.tkh-flip-front-title-wrap {
	margin-top: auto;
	margin-bottom: auto;
}

.tkh-flip-title {
	font-family: var(--tkh-flip-font-display);
	font-weight: 800;
	font-size: clamp(24px, 2.4vw, 32px);
	line-height: 1.05;
	letter-spacing: -0.04em;
	margin: 0;
	color: var(--tkh-front-title-color, var(--tkh-card-title-color-front-preset, inherit));
}

.tkh-flip-subtitle {
	font-family: var(--tkh-flip-font-body);
	font-size: 14px;
	line-height: 1.4;
	margin-top: 8px;
	opacity: 0.85;
	color: inherit;
}

.tkh-flip-hint {
	font-style: normal;
	font-size: 12px;
	font-family: var(--tkh-flip-font-mono);
	letter-spacing: 1.5px;
	text-transform: uppercase;
	opacity: 0.7;
	display: inline-flex;
	align-items: center;
	gap: 8px;
	transition: opacity 0.3s ease, transform 0.3s ease;
	color: inherit;
}

.tkh-flip-hint-icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	font-size: 16px;
	line-height: 1;
	transition: transform 0.6s cubic-bezier(0.3, 1.4, 0.5, 1);
	color: inherit;
}

.tkh-flip-card:hover .tkh-flip-hint-icon {
	transform: rotate(180deg);
}

/* ==========================================================================
   6. Content Elements (Back)
   ========================================================================== */

.tkh-flip-back-content {
	display: flex;
	flex-direction: column;
	justify-content: center;
	width: 100%;
	height: 100%;
}

.tkh-flip-back-title {
	font-family: var(--tkh-flip-font-display);
	font-size: 19px;
	font-weight: 700;
	letter-spacing: -0.03em;
	margin: 0 0 10px 0;
	color: var(--tkh-back-heading-color, var(--tkh-flip-teal-d));
}

.tkh-flip-back-desc {
	font-family: var(--tkh-flip-font-body);
	font-size: 15.5px;
	line-height: 1.6;
	font-weight: 500;
	color: var(--tkh-back-desc-color, var(--tkh-flip-navy-d));
	margin: 0;
	overflow-wrap: break-word;
	word-break: break-word;
}

.tkh-flip-back-desc p {
	margin: 0 0 10px 0;
}

.tkh-flip-back-desc p:last-child {
	margin-bottom: 0;
}

/* Back text overflow options */
.tkh-flip-card.tkh-back-scroll .tkh-flip-back-content {
	overflow-y: auto;
	scrollbar-width: thin;
}

.tkh-flip-card.tkh-back-clamp .tkh-flip-back-desc {
	display: -webkit-box;
	-webkit-line-clamp: 6;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

/* Back Link / Button */
.tkh-flip-back-btn-wrap {
	margin-top: 16px;
}

.tkh-flip-btn {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	font-family: var(--tkh-flip-font-body);
	font-weight: 700;
	font-size: 14px;
	color: var(--tkh-flip-navy);
	text-decoration: none;
	transition: color 0.3s ease, transform 0.2s ease;
}

.tkh-flip-btn:hover {
	color: var(--tkh-flip-teal-d);
	transform: translateX(3px);
}

.tkh-flip-btn-circle {
	width: 28px;
	height: 28px;
	border-radius: 50%;
	background: var(--tkh-flip-teal);
	color: #ffffff;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	font-size: 14px;
	transition: background 0.3s ease, transform 0.3s ease;
}

.tkh-flip-btn:hover .tkh-flip-btn-circle {
	background: var(--tkh-flip-teal-d);
	transform: scale(1.1);
}

/* Stretched card link */
.tkh-flip-stretched-link {
	position: absolute;
	inset: 0;
	z-index: 4;
	pointer-events: auto;
}

/* ==========================================================================
   7. Image Layers & Overlays (Cover & Inline)
   ========================================================================== */

.tkh-flip-img-wrap {
	position: absolute !important;
	inset: 0 !important;
	top: 0 !important;
	left: 0 !important;
	right: 0 !important;
	bottom: 0 !important;
	width: 100% !important;
	height: 100% !important;
	border-radius: inherit;
	overflow: hidden;
	pointer-events: none;
	z-index: 0;
}

.tkh-flip-picture {
	display: block !important;
	position: absolute !important;
	inset: 0 !important;
	top: 0 !important;
	left: 0 !important;
	width: 100% !important;
	height: 100% !important;
}

.tkh-flip-bg-img,
.tkh-flip-picture img,
.tkh-flip-img-wrap img {
	position: absolute !important;
	inset: 0 !important;
	top: 0 !important;
	left: 0 !important;
	width: 100% !important;
	height: 100% !important;
	min-width: 100% !important;
	min-height: 100% !important;
	max-width: none !important;
	max-height: none !important;
	object-fit: cover;
	object-position: center;
	display: block !important;
	transform: scale(var(--tkh-img-scale, 1));
	transition: transform var(--tkh-img-zoom-dur, 0.6s) cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.4s ease, filter 0.4s ease;
}

.tkh-flip-card:hover .tkh-flip-bg-img,
.tkh-flip-card:hover .tkh-flip-picture img,
.tkh-flip-card:hover .tkh-flip-img-wrap img {
	transform: scale(var(--tkh-img-hover-scale, 1.06));
}

.tkh-flip-overlay {
	position: absolute !important;
	inset: 0 !important;
	top: 0 !important;
	left: 0 !important;
	width: 100% !important;
	height: 100% !important;
	pointer-events: none;
	z-index: 1;
	transition: background 0.4s ease, opacity 0.4s ease;
}

/* Face Content Layer when images/overlays exist */
.tkh-flip-face-inner {
	position: relative;
	z-index: 1;
	display: flex;
	flex-direction: column;
	justify-content: space-between;
	width: 100%;
	height: 100%;
}

/* Inline Images */
.tkh-flip-inline-img {
	max-width: 100%;
	height: auto;
	border-radius: 12px;
	margin-bottom: 12px;
	object-fit: cover;
	display: block;
}

/* High-Contrast Light Theme for faces with dark image overlays */
.tkh-flip-face.tkh-light-text {
	color: #ffffff;
}

.tkh-flip-face.tkh-light-text .tkh-flip-title {
	color: #ffffff;
	text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

.tkh-flip-face.tkh-light-text .tkh-flip-num,
.tkh-flip-face.tkh-light-text .tkh-flip-hint,
.tkh-flip-face.tkh-light-text .tkh-flip-eyebrow {
	color: rgba(255, 255, 255, 0.9);
	opacity: 1;
}

/* ==========================================================================
   8. Responsive Fallbacks (Fluid Variables, No Blanket !important)
   ========================================================================== */

/* Tablet (≤ 1024px) */
@media (max-width: 1024px) {
	.tkh-flip-grid {
		--tkh-cols-fallback: 2;
		--tkh-gap-fallback: 14px;
	}

	.tkh-flip-card {
		--tkh-height-fallback: 300px;
	}
}

/* Mobile (≤ 767px) */
@media (max-width: 767px) {
	.tkh-flip-grid {
		--tkh-cols-fallback: 1;
		--tkh-gap-fallback: 14px;
	}

	.tkh-flip-card {
		--tkh-height-fallback: 230px;
	}

	.tkh-flip-face {
		padding: 20px 18px;
	}
}

/* ==========================================================================
   9. RTL Support
   ========================================================================== */

[dir="rtl"] .tkh-flip-wrap,
.rtl .tkh-flip-wrap {
	direction: rtl;
	text-align: right;
}

[dir="rtl"] .tkh-flip-btn:hover {
	transform: translateX(-3px);
}

[dir="rtl"] .tkh-flip-card.tkh-axis-y.is-flipped .tkh-flip-inner {
	transform: rotateY(-180deg);
}

@media (hover: hover) and (pointer: fine) {
	[dir="rtl"] .tkh-flip-card.tkh-trigger-hover.tkh-axis-y:hover .tkh-flip-inner,
	[dir="rtl"] .tkh-flip-card.tkh-trigger-hover-click.tkh-axis-y:hover .tkh-flip-inner {
		transform: rotateY(-180deg);
	}
}

/* ==========================================================================
   10. Accessibility & Reduced Motion / 3D Fallback (Cross-Fade)
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
	.tkh-flip-card,
	.tkh-flip-inner,
	.tkh-flip-hint-icon,
	.tkh-flip-bg-img {
		transition: none !important;
		animation: none !important;
	}

	.tkh-flip-inner {
		transform-style: flat !important;
	}

	.tkh-flip-back {
		transform: none !important;
		opacity: 0;
		visibility: hidden;
		transition: opacity 0.3s ease, visibility 0.3s ease !important;
	}

	.tkh-flip-front {
		opacity: 1;
		visibility: visible;
		transition: opacity 0.3s ease, visibility 0.3s ease !important;
	}

	.tkh-flip-card.is-flipped .tkh-flip-back,
	.tkh-flip-card:hover .tkh-flip-back {
		opacity: 1;
		visibility: visible;
	}

	.tkh-flip-card.is-flipped .tkh-flip-front,
	.tkh-flip-card:hover .tkh-flip-front {
		opacity: 0;
		visibility: hidden;
	}
}

/* Flattened 3D Fallback (when an ancestor flattens preserve-3d) */
.tkh-flip-wrap.fallback-crossfade .tkh-flip-inner {
	transform-style: flat !important;
}

.tkh-flip-wrap.fallback-crossfade .tkh-flip-back {
	transform: none !important;
	opacity: 0;
	visibility: hidden;
	transition: opacity 0.35s ease, visibility 0.35s ease !important;
}

.tkh-flip-wrap.fallback-crossfade .tkh-flip-front {
	opacity: 1;
	visibility: visible;
	transition: opacity 0.35s ease, visibility 0.35s ease !important;
}

.tkh-flip-wrap.fallback-crossfade .tkh-flip-card.is-flipped .tkh-flip-back,
.tkh-flip-wrap.fallback-crossfade .tkh-flip-card:hover .tkh-flip-back {
	opacity: 1;
	visibility: visible;
}

.tkh-flip-wrap.fallback-crossfade .tkh-flip-card.is-flipped .tkh-flip-front,
.tkh-flip-wrap.fallback-crossfade .tkh-flip-card:hover .tkh-flip-front {
	opacity: 0;
	visibility: hidden;
}

/* ==========================================================================
   11. Layout Diagnostics Checker (Admins / Editor Only)
   ========================================================================== */

.tkh-flip-checker {
	margin-top: 30px;
	padding: 14px 18px;
	background: #171b45;
	color: #eaf7f6;
	border-radius: 12px;
	font-family: var(--tkh-flip-font-mono);
	font-size: 12px;
	line-height: 1.6;
	border-inline-start: 4px solid var(--tkh-flip-teal);
	box-shadow: 0 10px 25px rgba(15, 18, 51, 0.2);
}

.tkh-flip-checker-title {
	font-weight: 700;
	color: var(--tkh-flip-gold);
	margin-bottom: 6px;
	display: flex;
	align-items: center;
	gap: 8px;
}

.tkh-flip-checker-grid {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
	gap: 8px 16px;
}

.tkh-flip-checker-item span {
	color: #ffffff;
	font-weight: 600;
}

.tkh-flip-checker-warnings {
	margin-top: 8px;
	padding-top: 8px;
	border-top: 1px dashed rgba(255, 255, 255, 0.2);
	color: #ffb4a2;
}
