/**
 * Frontend CSS
 * 
 * @package CodeCapsule
 * @since 1.0.0
 */

/* Capsule Wrapper */
.codecapsule-wrapper {
	position: relative;
	margin: 20px 0;
	clear: both;
}

/* Iframe Styling */
.codecapsule-wrapper iframe.codecapsule-iframe {
	width: 100%;
	max-width: 100%;
	border: none;
	display: block;
	background: transparent;
	min-height: 100px;
	box-sizing: border-box;
	/* Smooth height transitions for auto-resize */
	transition: height 300ms ease-out;
}

/* Smooth height transition for auto-resize */
.codecapsule-wrapper iframe.codecapsule-iframe.codecapsule-resized {
	transition: height 300ms ease-out;
}

/* Respect reduced motion preference */
@media (prefers-reduced-motion: reduce) {
	.codecapsule-wrapper iframe.codecapsule-iframe {
		transition: none;
	}
	
	.codecapsule-wrapper iframe.codecapsule-iframe.codecapsule-resized {
		transition: none;
	}
}

/* Shadow DOM Container */
.codecapsule-shadow-container {
	position: relative;
	min-height: 100px;
}

/* Sub-capsule Wrapper - Isolation */
.codecapsule-sub-capsule-wrapper {
	position: relative;
	isolation: isolate;
	contain: layout style paint;
	/* Prevent CSS from leaking out */
	overflow: hidden;
	/* Reset any inherited styles that might conflict */
	box-sizing: border-box;
}

/* Responsive Design - Enhanced */
/* Tablet and below (max-width: 1024px) */
@media (max-width: 1024px) {
	.codecapsule-wrapper {
		margin: 18px 0;
	}
	
	.codecapsule-wrapper.codecapsule-card {
		padding: 20px;
		border-radius: 10px;
	}
	
	.codecapsule-wrapper iframe.codecapsule-iframe {
		min-height: 150px;
	}
}

/* Mobile and small tablets (max-width: 768px) */
@media (max-width: 768px) {
	.codecapsule-wrapper {
		margin: 15px 0;
		width: 100%;
		max-width: 100%;
		box-sizing: border-box;
	}

	.codecapsule-wrapper.codecapsule-card {
		padding: 16px;
		border-radius: 8px;
		box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
	}

	.codecapsule-wrapper.codecapsule-full-section {
		margin-left: -15px !important;
		margin-right: -15px !important;
		width: calc(100% + 30px) !important;
		max-width: calc(100% + 30px) !important;
	}
	
	.codecapsule-wrapper iframe.codecapsule-iframe {
		min-height: 200px;
	}
	
	.codecapsule-shadow-container {
		min-height: 200px;
	}
}

/* Small mobile (max-width: 480px) */
@media (max-width: 480px) {
	.codecapsule-wrapper {
		margin: 10px 0;
		width: 100%;
		max-width: 100%;
		box-sizing: border-box;
	}

	.codecapsule-wrapper.codecapsule-card {
		padding: 12px;
		border-radius: 6px;
		box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
	}

	.codecapsule-wrapper.codecapsule-full-section {
		margin-left: -10px !important;
		margin-right: -10px !important;
		width: calc(100% + 20px) !important;
		max-width: calc(100% + 20px) !important;
	}
	
	.codecapsule-wrapper iframe.codecapsule-iframe {
		min-height: 250px;
	}
	
	.codecapsule-shadow-container {
		min-height: 250px;
	}

	/* Reduce animation distance on mobile */
	.codecapsule-wrapper.fade-in {
		animation: codecapsule-fade-in-mobile 0.4s ease-out;
	}

	.codecapsule-wrapper.slide-in {
		animation: codecapsule-slide-in-mobile 0.4s ease-out;
	}
}

/* Very small mobile (max-width: 360px) */
@media (max-width: 360px) {
	.codecapsule-wrapper {
		margin: 8px 0;
	}
	
	.codecapsule-wrapper.codecapsule-card {
		padding: 10px;
		border-radius: 4px;
	}
	
	.codecapsule-wrapper.codecapsule-full-section {
		margin-left: -8px !important;
		margin-right: -8px !important;
		width: calc(100% + 16px) !important;
		max-width: calc(100% + 16px) !important;
	}
}

@keyframes codecapsule-fade-in-mobile {
	from {
		opacity: 0;
		transform: translateY(10px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

@keyframes codecapsule-slide-in-mobile {
	from {
		opacity: 0;
		transform: translateX(-15px);
	}
	to {
		opacity: 1;
		transform: translateX(0);
	}
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
	.codecapsule-wrapper.fade-in,
	.codecapsule-wrapper.slide-in {
		animation: none;
		opacity: 1;
	}

	.codecapsule-spinner {
		animation: codecapsule-spin 2s linear infinite;
	}
}

/* Loading State */
.codecapsule-wrapper.codecapsule-loading {
	position: relative;
	min-height: 200px;
}

.codecapsule-wrapper.codecapsule-loaded {
	opacity: 1;
}

/* Card Style */
.codecapsule-wrapper.codecapsule-card {
	background: #fff;
	border-radius: 12px;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08), 0 2px 4px rgba(0, 0, 0, 0.04);
	padding: 24px;
	overflow: hidden;
	transition: box-shadow 0.3s ease;
}

.codecapsule-wrapper.codecapsule-card:hover {
	box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12), 0 4px 8px rgba(0, 0, 0, 0.06);
}

.codecapsule-wrapper.codecapsule-card iframe,
.codecapsule-wrapper.codecapsule-card .codecapsule-shadow-container {
	border-radius: 8px;
}

/* Full Section Style */
.codecapsule-wrapper.codecapsule-full-section {
	width: 100% !important;
	max-width: 100% !important;
	margin-left: 0 !important;
	margin-right: 0 !important;
	padding: 0;
	clear: both;
}

.codecapsule-wrapper.codecapsule-full-section iframe {
	width: 100%;
}

/* Inline Style (Default) */
.codecapsule-wrapper:not(.codecapsule-card):not(.codecapsule-full-section) {
	/* Default inline styling */
}

/* Loading Indicator */
.codecapsule-loading-indicator {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	background: rgba(255, 255, 255, 0.9);
	z-index: 10;
	border-radius: inherit;
}

.codecapsule-spinner {
	width: 40px;
	height: 40px;
	border: 4px solid #f3f3f3;
	border-top: 4px solid #d76b00;
	border-radius: 50%;
	animation: codecapsule-spin 1s linear infinite;
}

@keyframes codecapsule-spin {
	0% { transform: rotate(0deg); }
	100% { transform: rotate(360deg); }
}

/* Fade In Animation */
.codecapsule-wrapper.fade-in {
	animation: codecapsule-fade-in 0.6s ease-out;
}

@keyframes codecapsule-fade-in {
	from {
		opacity: 0;
		transform: translateY(20px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

/* Slide In Animation */
.codecapsule-wrapper.slide-in {
	animation: codecapsule-slide-in 0.6s ease-out;
}

@keyframes codecapsule-slide-in {
	from {
		opacity: 0;
		transform: translateX(-30px);
	}
	to {
		opacity: 1;
		transform: translateX(0);
	}
}

/* No Animation */
.codecapsule-wrapper.codecapsule-no-animation {
	animation: none !important;
}

/* No Gap - Remove gap between columns and spacing */
.codecapsule-wrapper.codecapsule-no-gap {
	margin-top: 0 !important;
	margin-bottom: 0 !important;
	padding-top: 0 !important;
	padding-bottom: 0 !important;
}

.codecapsule-wrapper.codecapsule-no-gap * {
	gap: 0 !important;
	column-gap: 0 !important;
	row-gap: 0 !important;
}

/* No Gap for grid layouts */
.codecapsule-wrapper.codecapsule-no-gap [style*="display: grid"],
.codecapsule-wrapper.codecapsule-no-gap [style*="display:grid"],
.codecapsule-wrapper.codecapsule-no-gap .grid,
.codecapsule-wrapper.codecapsule-no-gap [class*="grid"] {
	gap: 0 !important;
	column-gap: 0 !important;
	row-gap: 0 !important;
}

/* No Gap for flexbox layouts */
.codecapsule-wrapper.codecapsule-no-gap [style*="display: flex"],
.codecapsule-wrapper.codecapsule-no-gap [style*="display:flex"],
.codecapsule-wrapper.codecapsule-no-gap .flex,
.codecapsule-wrapper.codecapsule-no-gap [class*="flex"] {
	gap: 0 !important;
	column-gap: 0 !important;
	row-gap: 0 !important;
}

/* Remove spacing from first and last child elements */
.codecapsule-wrapper.codecapsule-no-gap > *:first-child {
	margin-top: 0 !important;
	padding-top: 0 !important;
}

.codecapsule-wrapper.codecapsule-no-gap > *:last-child {
	margin-bottom: 0 !important;
	padding-bottom: 0 !important;
}

/* Error State */
.codecapsule-wrapper.codecapsule-error {
	padding: 15px;
	background: #fff3cd;
	border-left: 4px solid #ffc107;
	margin: 20px 0;
	border-radius: 4px;
}

.codecapsule-error-message {
	color: #856404;
	font-weight: 500;
	margin-top: 10px;
}

