/**
 * Test Drive Grid Styles
 */

/* Main Container */
.test-drive-grid-wrapper {
	max-width: 1400px;
	margin: 0 auto;
	padding: 20px;
	/* Mobile scroll fix - allow normal vertical scrolling */
	touch-action: pan-y;
	overscroll-behavior: contain;
}

/* Controls Row - Search Left, Tabs Right */
.tdg-controls-row {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 20px;
	margin-bottom: 30px;
	padding-bottom: 20px;
	border-bottom: 1px solid #e0e0e0;
}

/* Tab Navigation */
.tdg-tabs {
	display: flex;
	flex-wrap: wrap;
	gap: 10px;
	justify-content: flex-end;
	align-items: center;
}

.tdg-tab {
	background: #ffffff;
	border: 1px solid #d0d0d0;
	border-radius: 6px;
	padding: 10px 20px;
	font-size: 14px;
	font-weight: 500;
	color: #333333;
	cursor: pointer;
	transition: all 0.3s ease;
	white-space: nowrap;
}

.tdg-tab:hover {
	background: #f5f5f5;
	border-color: #999999;
}

.tdg-tab.active {
	background: #0066cc;
	color: #ffffff;
	border-color: #0066cc;
}

/* Search Field */
.tdg-search-wrapper {
	position: relative;
	max-width: 400px;
	flex-shrink: 0;
}

.tdg-search-input {
	width: 100%;
	padding: 12px 40px 12px 16px;
	font-size: 15px;
	border: 1px solid #d0d0d0;
	border-radius: 6px;
	transition: all 0.3s ease;
	background: #ffffff;
}

.tdg-search-input:focus {
	outline: none;
	border-color: #0066cc;
	box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.1);
}

.tdg-search-input::placeholder {
	color: #999999;
}

.tdg-search-icon {
	position: absolute;
	right: 12px;
	top: 50%;
	transform: translateY(-50%);
	color: #666666;
	pointer-events: none;
}

/* Loading Indicator */
.tdg-loading {
	text-align: center;
	padding: 40px;
}

.tdg-spinner {
	border: 3px solid #f3f3f3;
	border-top: 3px solid #0066cc;
	border-radius: 50%;
	width: 40px;
	height: 40px;
	animation: tdg-spin 1s linear infinite;
	margin: 0 auto;
}

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

/* Grid Layout */
.tdg-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
	gap: 24px;
	margin-bottom: 40px;
	/* Mobile scroll fix - allow vertical pan and pinch zoom */
	touch-action: pan-y pinch-zoom;
	/* Ensure grid doesn't collapse or expand unexpectedly */
	width: 100%;
	/* Prevent content from affecting column widths */
	grid-auto-rows: minmax(min-content, max-content);
}

/* Tile Size Variations */
/* Small tiles - 4-5 per row on desktop */
.tdg-size-small .tdg-grid {
	grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
	gap: 20px;
}

/* Medium tiles - 3-4 per row (default) */
.tdg-size-medium .tdg-grid {
	grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
	gap: 24px;
}

/* Large tiles - 2-3 per row */
.tdg-size-large .tdg-grid {
	grid-template-columns: repeat(auto-fill, minmax(450px, 1fr));
	gap: 28px;
}

/* Extra Large tiles - 1-2 per row */
.tdg-size-xlarge .tdg-grid {
	grid-template-columns: repeat(auto-fill, minmax(600px, 1fr));
	gap: 32px;
}

/* Custom size using CSS variable */
.tdg-size-custom .tdg-grid {
	grid-template-columns: repeat(auto-fill, minmax(var(--tdg-tile-min-width, 350px), 1fr));
}

/* Fixed columns mode - CRITICAL: minmax(0, 1fr) prevents content from expanding columns */
.tdg-columns-1 .tdg-grid { grid-template-columns: repeat(1, minmax(0, 1fr)); }
.tdg-columns-2 .tdg-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tdg-columns-3 .tdg-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tdg-columns-4 .tdg-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.tdg-columns-5 .tdg-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.tdg-columns-6 .tdg-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }

/* Ensure tiles in fixed column mode don't expand beyond their column */
.tdg-columns-1 .tdg-tile,
.tdg-columns-2 .tdg-tile,
.tdg-columns-3 .tdg-tile,
.tdg-columns-4 .tdg-tile,
.tdg-columns-5 .tdg-tile,
.tdg-columns-6 .tdg-tile {
	max-width: 100%;
	min-width: 0;
	width: 100%;
	box-sizing: border-box;
	overflow: hidden;
}

/* CRITICAL: Ensure all grid children respect column boundaries */
.tdg-grid > * {
	min-width: 0;
	max-width: 100%;
}

/* Tile Styles */
.tdg-tile {
	background: #ffffff;
	border: 1px solid #e0e0e0;
	border-radius: 8px;
	padding: 24px;
	transition: all 0.3s ease;
	display: flex;
	flex-direction: column;
	position: relative;
	box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
	/* Mobile scroll fix - allow normal touch behavior */
	touch-action: pan-y;
	/* CRITICAL: Ensure tiles fill grid cell properly and don't overflow */
	width: 100%;
	min-width: 0;
	max-width: 100%;
	box-sizing: border-box;
	/* Prevent content from expanding the tile */
	overflow: hidden;
}

/* Hidden tiles should not affect grid layout */
.tdg-tile.tdg-tile-hidden {
	display: none !important;
}

.tdg-tile:hover {
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
	transform: translateY(-2px);
	border-color: #0066cc;
}

/* Tile Header */
.tdg-tile-header {
	display: flex;
	justify-content: center;
	align-items: center;
	margin-bottom: 16px;
	/* Prevent header from expanding tile width */
	min-width: 0;
	max-width: 100%;
}

.tdg-tile-title {
	font-size: 18px;
	font-weight: 600;
	color: #1a1a1a;
	margin: 0;
	line-height: 1.4;
	text-align: center;
	/* Prevent long titles from expanding tile width */
	min-width: 0;
	max-width: 100%;
	overflow-wrap: break-word;
	word-wrap: break-word;
}

/* Product Tags */
.tdg-tile-tags {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin-bottom: 16px;
}

.tdg-tag {
	display: inline-block;
	background: #f0f4f8;
	color: #2c5282;
	padding: 4px 12px;
	border-radius: 4px;
	font-size: 12px;
	font-weight: 500;
	text-transform: uppercase;
	letter-spacing: 0.5px;
}

/* Clickable tag links (v1.6.5.18, updated v1.6.5.19)
 * By default, linked tags look the same as non-linked tags
 * Only the hover state changes to indicate clickability
 */
a.tdg-tag-link {
	text-decoration: none;
	transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease;
	cursor: pointer;
	/* Same colors as .tdg-tag by default */
	background: #f0f4f8;
	color: #2c5282;
}

a.tdg-tag-link:hover {
	background: #2c5282;
	color: #ffffff;
	transform: translateY(-1px);
}

a.tdg-tag-link:active {
	transform: translateY(0);
}

/* Tile Content */
.tdg-tile-content {
	flex: 1;
	color: #4a4a4a;
	font-size: 14px;
	line-height: 1.6;
	margin-bottom: 20px;
	/* Prevent content from expanding tile width */
	min-width: 0;
	max-width: 100%;
	overflow-wrap: break-word;
	word-wrap: break-word;
}

.tdg-tile-content p:last-child {
	margin-bottom: 0;
}

/* Tile Footer */
/* Tile Footer - Button Container */
.tdg-tile-footer {
	margin-top: auto;
	padding-top: 16px;
	border-top: 1px solid #f0f0f0;
	display: flex;
	gap: 12px;
	align-items: center;
	/* Prevent footer from expanding tile width */
	min-width: 0;
	max-width: 100%;
	flex-wrap: wrap;
}

/* Base Button Styles - Both buttons same style */
.tdg-button {
	display: inline-block;
	padding: 10px 24px;
	border-radius: 6px;
	text-decoration: none;
	font-weight: 500;
	font-size: 14px;
	transition: all 0.3s ease;
	border: none;
	cursor: pointer;
	background: #0066cc;
	color: #ffffff;
}

/* Button Hover - Same for both */
.tdg-button:hover {
	background: #0052a3;
	color: #ffffff !important;
	transform: translateY(-1px);
	box-shadow: 0 2px 8px rgba(0, 102, 204, 0.3);
}

.tdg-button:active {
	transform: translateY(0);
}

/* Legacy class names for backward compatibility */
.tdg-launch-button {
	background: #0066cc;
	color: #ffffff;
}

.tdg-launch-button:hover {
	background: #0052a3;
	color: #ffffff !important;
	transform: translateY(-1px);
	box-shadow: 0 2px 8px rgba(0, 102, 204, 0.3);
}

.tdg-launch-button:active {
	transform: translateY(0);
}

.tdg-learn-more-button {
	background: #0066cc;
	color: #ffffff;
}

.tdg-learn-more-button:hover {
	background: #0052a3;
	color: #ffffff !important;
	transform: translateY(-1px);
	box-shadow: 0 2px 8px rgba(0, 102, 204, 0.3);
}

.tdg-learn-more-button:active {
	transform: translateY(0);
}

/* Custom button (v1.6.5.17) */
.tdg-custom-button {
	background: #0066cc;
	color: #ffffff;
}

.tdg-custom-button:hover {
	background: #0052a3;
	color: #ffffff !important;
	transform: translateY(-1px);
	box-shadow: 0 2px 8px rgba(0, 102, 204, 0.3);
}

.tdg-custom-button:active {
	transform: translateY(0);
}

/* No Results */
.tdg-no-results {
	text-align: center;
	padding: 60px 20px;
	color: #666666;
	font-size: 16px;
	grid-column: 1 / -1;
}

/* Pagination Controls */
.tdg-pagination-wrapper {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	margin-top: 30px;
	padding: 20px 0;
}

.tdg-pagination-btn {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 8px 14px;
	background: #f0f0f0;
	border: 1px solid #ddd;
	border-radius: 4px;
	cursor: pointer;
	font-size: 14px;
	font-weight: 500;
	color: #333;
	transition: all 0.2s ease;
	white-space: nowrap;
}

.tdg-pagination-btn:hover:not(:disabled) {
	background: #e0e0e0;
	border-color: #ccc;
}

.tdg-pagination-btn:disabled {
	opacity: 0.5;
	cursor: not-allowed;
	background: #f5f5f5;
}

.tdg-pagination-arrow {
	font-size: 16px;
}

.tdg-pagination-separator {
	color: #999;
	font-size: 14px;
	padding: 0 4px;
}

.tdg-page-numbers {
	display: flex;
	gap: 4px;
	align-items: center;
}

.tdg-page-number {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 32px;
	height: 32px;
	padding: 6px 10px;
	background: #f0f0f0;
	border: 1px solid #ddd;
	border-radius: 4px;
	cursor: pointer;
	font-size: 14px;
	font-weight: 500;
	color: #333;
	transition: all 0.2s ease;
}

.tdg-page-number:hover {
	background: #e0e0e0;
	border-color: #ccc;
}

.tdg-page-number.active {
	background: #0066cc;
	border-color: #0066cc;
	color: #ffffff;
	cursor: default;
}

.tdg-page-number.active:hover {
	background: #0066cc;
	border-color: #0066cc;
}

/* Responsive Design */
@media (max-width: 1200px) {
	.tdg-grid {
		grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
		gap: 20px;
	}
	
	/* Adjust preset sizes for tablet */
	.tdg-size-small .tdg-grid {
		grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
	}
	
	.tdg-size-large .tdg-grid {
		grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
	}
	
	.tdg-size-xlarge .tdg-grid {
		grid-template-columns: repeat(auto-fill, minmax(500px, 1fr));
	}
	
	/* Fixed columns adjust on tablet */
	.tdg-columns-5 .tdg-grid,
	.tdg-columns-6 .tdg-grid { 
		grid-template-columns: repeat(3, 1fr); 
	}
	
	.tdg-columns-4 .tdg-grid { 
		grid-template-columns: repeat(3, 1fr); 
	}
}

@media (max-width: 768px) {
	.test-drive-grid-wrapper {
		padding: 15px;
	}

	/* Stack controls on mobile */
	.tdg-controls-row {
		flex-direction: column;
		align-items: stretch;
		gap: 15px;
	}

	.tdg-search-wrapper {
		max-width: 100%;
	}
	
	/* Prevent iOS zoom on input focus */
	.tdg-search-input {
		font-size: 16px; /* Prevents iOS auto-zoom */
	}

	.tdg-tabs {
		gap: 8px;
		justify-content: flex-start;
	}

	.tdg-tab {
		font-size: 13px;
		padding: 8px 16px;
	}

	/* All tiles become single column on mobile */
	.tdg-grid,
	.tdg-size-small .tdg-grid,
	.tdg-size-medium .tdg-grid,
	.tdg-size-large .tdg-grid,
	.tdg-size-xlarge .tdg-grid,
	.tdg-columns-1 .tdg-grid,
	.tdg-columns-2 .tdg-grid,
	.tdg-columns-3 .tdg-grid,
	.tdg-columns-4 .tdg-grid,
	.tdg-columns-5 .tdg-grid,
	.tdg-columns-6 .tdg-grid {
		grid-template-columns: 1fr;
		gap: 16px;
	}

	.tdg-tile {
		padding: 20px;
	}

	.tdg-tile-title {
		font-size: 16px;
	}

	/* Pagination responsive */
	.tdg-pagination-wrapper {
		flex-wrap: wrap;
		gap: 6px;
	}

	.tdg-pagination-btn {
		font-size: 13px;
		padding: 6px 10px;
	}

	.tdg-page-number {
		min-width: 28px;
		height: 28px;
		font-size: 13px;
		padding: 4px 8px;
	}
}

@media (max-width: 480px) {
	.tdg-tabs {
		overflow-x: auto;
		flex-wrap: nowrap;
		-webkit-overflow-scrolling: touch;
		padding-bottom: 10px;
		/* Mobile scroll fix - only capture horizontal swipes on tabs */
		touch-action: pan-x;
		overscroll-behavior-x: contain;
	}

	.tdg-tab {
		flex-shrink: 0;
	}

	.tdg-tile-header {
		align-items: center;
	}
}

/* Fade-in Animation */
@keyframes fadeIn {
	from {
		opacity: 0;
		transform: translateY(10px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

.tdg-tile {
	animation: fadeIn 0.4s ease-out;
}

/* Tile Image Styles */
.tdg-tile-image {
	margin: 16px -24px 20px -24px;
	overflow: hidden;
	border-radius: 8px;
	background: #f5f5f5;
	position: relative;
	/* CRITICAL: Use calc to ensure image container doesn't cause grid overflow */
	width: calc(100% + 48px);
	max-width: calc(100% + 48px);
	box-sizing: border-box;
}

.tdg-tile-image img {
	width: 100%;
	height: 200px;
	object-fit: cover;
	display: block;
	transition: transform 0.3s ease;
	/* CRITICAL: Prevent image from affecting grid column width */
	max-width: 100%;
	min-width: 0;
}

.tdg-tile:hover .tdg-tile-image img {
	transform: scale(1.05);
}

/* Image overlay gradient for better text readability if needed */
.tdg-tile-image::after {
	content: '';
	position: absolute;
	bottom: 0;
	left: 0;
	right: 0;
	height: 50px;
	background: linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.1));
	pointer-events: none;
}

/* Mobile image adjustments */
@media (max-width: 768px) {
	.tdg-tile-image {
		margin: 16px -20px 16px -20px;
	}
	
	.tdg-tile-image img {
		height: 160px;
	}
}

@media (max-width: 480px) {
	.tdg-tile-image {
		margin: 12px -20px 12px -20px;
	}
	
	.tdg-tile-image img {
		height: 140px;
	}
}

/* Company Name Plate (v1.6.5.14, extended v1.6.5.16) */
.tdg-company-name {
	background-color: #f0f0f0;
	color: #333333;
	padding: 8px 12px;
	margin: 0 -24px 16px -24px;
	font-size: 0.9em;
	font-weight: 600;
	text-align: center;
	border-bottom: 1px solid #e0e0e0;
	/* CRITICAL: Use calc to ensure company name doesn't cause grid overflow */
	width: calc(100% + 48px);
	max-width: calc(100% + 48px);
	box-sizing: border-box;
}

/* Company Name Label (v1.6.5.16) */
.tdg-company-name-label {
	font-weight: 400;
	opacity: 0.8;
}

@media (max-width: 768px) {
	.tdg-company-name {
		margin: 0 -20px 12px -20px;
		padding: 6px 10px;
		font-size: 0.85em;
		/* Recalculate width for smaller padding */
		width: calc(100% + 40px);
		max-width: calc(100% + 40px);
	}
}

@media (max-width: 480px) {
	.tdg-company-name {
		margin: 0 -20px 10px -20px;
		padding: 5px 8px;
		font-size: 0.8em;
	}
}

/* Print Styles */
@media print {
	.tdg-tabs,
	.tdg-search-wrapper,
	.tdg-pagination-wrapper,
	.tdg-launch-button {
		display: none;
	}

	.tdg-tile {
		break-inside: avoid;
		box-shadow: none;
		border: 1px solid #ddd;
	}
	
	.tdg-tile-image img {
		height: auto;
		max-height: 150px;
	}
}
