/* Brand Chart Shortcodes Styling - Minimal additions to existing patterns */

/* Ensure chart containers have proper dimensions */
.chart-container {
	width: 100%;
	height: 400px;
	position: relative;
	overflow: hidden;
	margin-bottom: 20px;
	/* Extra space for scrollable legends */
}

/* Custom Legend - above chart, centered, minimal */
.chart-custom-legend {
	display: flex;
	justify-content: center;
	margin: 0 0 12px;
	position: relative;
	width: 100%;
	padding: 0 8px;
	box-sizing: border-box;
}

.chart-custom-legend .legend-items {
	display: flex;
	flex-wrap: wrap;
	gap: 8px 12px;
	align-items: center;
	justify-content: center;
	position: relative;
	max-width: 100%;
}

.chart-custom-legend .legend-item {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	font-size: 13px;
	color: #374151;
	white-space: nowrap;
	flex-shrink: 0;
}

/* Clickable legend items (host and comparison) */
.chart-custom-legend .legend-item-host,
.chart-custom-legend .legend-item-comparison {
	cursor: pointer;
	padding: 4px 8px;
	border-radius: 6px;
	transition: opacity 0.15s ease, background 0.15s ease;
	user-select: none;
}

.chart-custom-legend .legend-item-host:hover,
.chart-custom-legend .legend-item-comparison:hover {
	background: rgba(0, 0, 0, 0.04);
}

/* Disabled state - series hidden from chart */
.chart-custom-legend .legend-item-disabled {
	opacity: 0.5;
}

.chart-custom-legend .legend-item-disabled .legend-label {
	text-decoration: line-through;
}

.chart-custom-legend .legend-item-disabled .legend-color {
	opacity: 0.4;
}

.chart-custom-legend .legend-color {
	width: 12px;
	height: 12px;
	border-radius: 2px;
	flex-shrink: 0;
}

.chart-custom-legend .legend-color-add {
	width: 16px;
	height: 16px;
	display: flex;
	align-items: center;
	justify-content: center;
	background: #e5e7eb;
	color: #6b7280;
	font-size: 14px;
	font-weight: 500;
	border-radius: 50%;
}

.chart-custom-legend .legend-add-compare {
	cursor: pointer;
	padding: 4px 6px;
	border-radius: 6px;
	background: #f9fafb;
	border: 1px solid #e5e7eb;
	transition: background 0.15s ease, border-color 0.15s ease;
	gap: 1px;
}

.chart-custom-legend .legend-add-compare:hover {
	background: #f3f4f6;
	border-color: #9ca3af;
}

.chart-custom-legend .legend-caret {
	color: #9ca3af;
	margin-left: 2px;
	display: inline-block;
	transition: transform 0.2s ease;
	flex-shrink: 0;
}

/* Rotate caret when dropdown is open - point left */
.chart-custom-legend .legend-add-compare.open .legend-caret {
	transform: rotate(90deg);
}

.chart-custom-legend .legend-item-comparison button.legend-item-clear {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 16px;
	height: 16px;
	border: none;
	background: transparent;
	border-radius: 50%;
	cursor: pointer;
	font-size: 14px;
	line-height: 1;
	color: #9ca3af;
	padding: 0;
	margin-left: 4px;
	opacity: 1;
	transform: translateX(-4px);
	transition: opacity 0.15s ease, transform 0.15s ease, color 0.15s ease, background 0.15s ease;
	box-shadow: none;
}

.chart-custom-legend .legend-item-comparison button.legend-item-clear:hover {
	color: #374151;
	background: rgba(0, 0, 0, 0.06);
}

/* Dropdown for brand selection */
.chart-custom-legend .legend-dropdown {
	position: absolute;
	top: 100%;
	left: 50%;
	transform: translateX(-50%);
	margin-top: 8px;
	width: 280px;
	max-height: 300px;
	background: #fff;
	border: 1px solid #d1d5db;
	border-radius: 8px;
	box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
	z-index: 1000;
	display: none;
	flex-direction: column;
}

.chart-custom-legend .legend-dropdown.open {
	display: flex;
}

.chart-custom-legend .legend-search-input {
	padding: 10px 12px;
	border: none !important;
	border-bottom: 1px solid #e5e7eb !important;
	font-size: 13px;
	outline: none !important;
	border-radius: 8px 8px 0 0;
	box-shadow: none !important;
}

.chart-custom-legend .legend-search-input:focus {
	border: none !important;
	border-bottom: 1px solid #9ca3af !important;
	outline: none !important;
	box-shadow: none !important;
}

.chart-custom-legend .legend-dropdown-list {
	max-height: 240px;
	overflow-y: auto;
}

.chart-custom-legend .legend-dropdown-item {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	padding: 8px 12px;
	font-size: 13px;
	cursor: pointer;
	transition: background 0.1s ease;
}

.chart-custom-legend .legend-dropdown-item:hover {
	background: #f3f4f6;
}

.chart-custom-legend .legend-dropdown-item:active {
	background: #e5e7eb;
}

.chart-custom-legend .dropdown-brand-name {
	flex: 1;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.chart-custom-legend .dropdown-ticker-tag {
	flex-shrink: 0;
	padding: 2px 6px;
	background: #f0f4ff;
	color: #1a4e96;
	font-size: 11px;
	font-weight: 500;
	border-radius: 4px;
}

/* No results message for legend dropdown */
.chart-custom-legend .legend-dropdown-no-results {
	padding: 12px;
	text-align: center;
	color: #9ca3af;
	font-size: 13px;
	font-style: italic;
	white-space: nowrap;
}

.chart-lightbox-modal {
	position: fixed;
	inset: 0;
	display: none;
	align-items: center;
	justify-content: center;
	z-index: 9999;
}

.chart-lightbox-modal.active {
	display: flex;
}

.chart-lightbox-overlay {
	position: absolute;
	inset: 0;
	background: rgba(0, 0, 0, 0.55);
}

.chart-lightbox-content-wrapper {
	position: relative;
	z-index: 1;
	max-width: 1200px;
	width: 90%;
	max-height: 90vh;
	background: #fff;
	border-radius: 8px;
	box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
	padding: 16px;
	overflow: auto;
}

.chart-lightbox-content {
	min-height: 420px;
}

.chart-lightbox-modal .chart-lightbox-content-wrapper button.chart-lightbox-close {
	position: absolute;
	top: 12px;
	right: 12px;
	width: 32px;
	height: 32px;
	display: flex;
	align-items: center;
	justify-content: center;
	background: rgba(0, 0, 0, 0.05);
	border: none;
	border-radius: 50%;
	font-size: 20px;
	font-weight: 300;
	line-height: 1;
	color: #374151;
	cursor: pointer;
	padding: 0;
	box-shadow: none;
	transition: background 0.15s ease, color 0.15s ease;
	z-index: 10;
}

.chart-lightbox-modal .chart-lightbox-content-wrapper button.chart-lightbox-close:hover {
	background: rgba(0, 0, 0, 0.1);
	color: #111;
}

.chart-lightbox-modal .chart-lightbox-content-wrapper button.chart-lightbox-close:focus {
	outline: 2px solid #9ca3af;
	outline-offset: 2px;
}

/* Lightbox modal overrides - remove shadows and contain chart */
.chart-lightbox-modal .brand-chart-card,
.chart-lightbox-modal .chart-card,
.chart-lightbox-content .brand-chart-card,
.chart-lightbox-content .chart-card {
	box-shadow: none !important;
	border: none !important;
	margin: 0 !important;
	padding: 0 !important;
	background: transparent !important;
	width: 100% !important;
	max-width: 100% !important;
}

.chart-lightbox-modal .chart-container,
.chart-lightbox-modal .brand-chart-container,
.chart-lightbox-content .chart-container,
.chart-lightbox-content .brand-chart-container {
	width: 100% !important;
	max-width: 100% !important;
	height: 500px !important;
	min-height: 400px !important;
	overflow: hidden !important;
}

.chart-lightbox-content-wrapper {
	overflow: hidden !important;
}

.chart-lightbox-content-wrapper .brand-chart-card {
	width: 100%;
}

/* Ensure ECharts canvas stays within bounds in lightbox */
.chart-lightbox-modal canvas,
.chart-lightbox-content canvas {
	max-width: 100% !important;
}

/* Hide tooltip overflow in lightbox */
.chart-lightbox-modal [style*="position: absolute"],
.chart-lightbox-content [style*="position: absolute"] {
	max-width: 100%;
}

/* Lightbox chart specific sizing */
.lightbox-chart.brand-chart-card {
	box-shadow: none !important;
	border: none !important;
}

.lightbox-chart .brand-chart-container {
	height: 500px !important;
}

/* Lightbox legend - interactive, same toggle behavior as chart cards */
.lightbox-legend {
	pointer-events: auto;
}

.lightbox-legend .legend-item-host,
.lightbox-legend .legend-item-comparison {
	cursor: pointer;
}

/* MSA Revenue Chart specific adjustments for comparison charts */
.chart-container[id*="msa-revenue"] {
	height: 450px;
	/* Extra height for legend space */
}

/* ECharts legend improvements for comparison charts */
.chart-container .echarts-legend {
	overflow: visible !important;
}

/* Ensure scrollable legends have proper spacing */
.chart-container .echarts-legend-scroll {
	min-height: 30px;
	padding: 5px 0;
}

/* Prevent legend text overflow */
.chart-container .echarts-legend-item {
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	max-width: 120px;
}

.chart-loading {
	display: flex;
	align-items: center;
	justify-content: center;
	height: 300px;
	max-height: 400px;
	flex-direction: column;
	gap: 12px;
	color: #888;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
	font-size: 13px;
}

.chart-loading .spinner {
	width: 32px;
	height: 32px;
	border: 3px solid #f0f0f0;
	border-top: 3px solid #6212B7;
	border-radius: 50%;
	animation: spin 0.8s linear infinite;
}

@keyframes spin {
	0% {
		transform: rotate(0deg);
	}

	100% {
		transform: rotate(360deg);
	}
}

.chart-error {
	display: flex;
	align-items: center;
	justify-content: center;
	height: 100%;
	color: #d63384;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
	font-size: 14px;
	text-align: center;
	padding: 20px;
}

/* Ensure charts render properly */
.chart-container canvas {
	width: 100% !important;
	height: 100% !important;
}

/* Responsive adjustments */
@media (max-width: 768px) {
	.chart-container {
		height: 300px;
	}

	.chart-loading {
		height: 250px;
		gap: 10px;
	}

	.chart-loading .spinner {
		width: 24px;
		height: 24px;
		border-width: 2px;
	}
}

/* ========================================
   Page-Level Brand Comparison Component
   ======================================== */

.page-compare-wrapper {
	display: flex;
	flex-wrap: wrap;
	align-items: flex-start;
	gap: 12px;
	margin-top: 16px;
	position: relative;
	width: fit-content;
	max-width: 100%;
	padding: 10px 14px;
	background: #f9fafb;
	border: 1px solid #e5e7eb;
	border-radius: 10px;
}

.page-compare-trigger {
	display: flex;
	align-items: center;
	gap: 8px 12px;
	flex-wrap: wrap;
	flex: 1;
	min-width: 0;
}

.page-compare-btn {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 6px 10px;
	border: 1px solid #d1d5db;
	border-radius: 6px;
	background: #fff;
	cursor: pointer;
	font-size: 13px;
	color: #374151;
	transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
	user-select: none;
	box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.page-compare-btn:hover {
	border-color: #9ca3af;
	background: #fff;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.page-compare-btn.open {
	border-color: #9ca3af;
	background: #fff;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.page-compare-icon {
	font-size: 16px;
	font-weight: 500;
	color: #6b7280;
}

.page-compare-label {
	font-weight: 500;
}

.page-compare-caret {
	width: 10px;
	height: 6px;
	color: #9ca3af;
	transition: transform 0.2s ease;
}

.page-compare-btn.open .page-compare-caret {
	transform: rotate(90deg);
}

/* Selected brand pills */
.page-compare-pills {
	display: flex;
	align-items: center;
	gap: 8px;
	flex-wrap: wrap;
}

.page-compare-pill {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 5px 10px;
	background: #fff;
	border: 1px solid #e5e7eb;
	border-radius: 16px;
	font-size: 12px;
	color: #374151;
	box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.page-compare-pill-color {
	width: 8px;
	height: 8px;
	border-radius: 50%;
	flex-shrink: 0;
}

.page-compare-pill-name {
	white-space: nowrap;
}

.page-compare-pill-remove {
	display: inline-flex !important;
	align-items: center !important;
	justify-content: center !important;
	width: 16px !important;
	height: 16px !important;
	border: none !important;
	background: transparent !important;
	border-radius: 50% !important;
	cursor: pointer !important;
	font-size: 12px !important;
	line-height: 1 !important;
	color: #9ca3af !important;
	transition: background 0.15s ease, color 0.15s ease !important;
	padding: 0 !important;
	box-shadow: none !important;
}

.page-compare-pill-remove:hover {
	background: rgba(0, 0, 0, 0.08) !important;
	color: #374151 !important;
}

/* Dropdown */
.page-compare-dropdown {
	display: none;
	position: absolute;
	top: 100%;
	left: 0;
	margin-top: 8px;
	min-width: 280px;
	max-width: 350px;
	background: #fff;
	border: 1px solid #e5e7eb;
	border-radius: 8px;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
	z-index: 100;
	flex-direction: column;
}

.page-compare-dropdown.open {
	display: flex;
}

.page-compare-search {
	width: 100%;
	padding: 10px 12px;
	border: none;
	border-bottom: 1px solid #e5e7eb;
	border-radius: 8px 8px 0 0;
	font-size: 14px;
	outline: none;
	background: #fff;
	box-sizing: border-box;
	-webkit-appearance: none;
	-moz-appearance: none;
	appearance: none;
}

.page-compare-search:focus {
	border-bottom-color: #9ca3af;
	outline: none;
	box-shadow: none;
}

.page-compare-list {
	max-height: 280px;
	overflow-y: auto;
}

.page-compare-item {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 10px 12px;
	cursor: pointer;
	transition: background 0.1s ease;
}

.page-compare-item:hover {
	background: #f3f4f6;
}

.page-compare-item.selected {
	background: #f9fafb;
}

.page-compare-item.selected::after {
	content: '';
	width: 16px;
	height: 16px;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%236b7280'%3E%3Cpath fill-rule='evenodd' d='M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z' clip-rule='evenodd'/%3E%3C/svg%3E");
	background-size: contain;
	background-repeat: no-repeat;
	flex-shrink: 0;
}

.page-compare-item-name {
	flex: 1 1 auto;
	font-size: 0.9rem;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	min-width: 0;
	/* Allow flex item to shrink below content size */
}

.page-compare-item-ticker {
	flex-shrink: 0;
	font-size: 10px;
	font-weight: 500;
	background: #e0f2fe;
	color: #0369a1;
	padding: 2px 5px;
	border-radius: 3px;
	margin-left: 8px;
	white-space: nowrap;
}

/* No results message for page compare dropdown */
.page-compare-no-results {
	padding: 12px;
	text-align: center;
	color: #9ca3af;
	font-size: 13px;
	font-style: italic;
}

/* 
 * When page-level comparison is active, individual chart compare controls 
 * still work. Changes sync between page-level and chart-level.
 */

/* ========================================
   Responsive Adjustments for Comparison UI
   ======================================== */

/* Tablet and smaller */
@media (max-width: 768px) {
	.chart-custom-legend {
		padding: 0 4px;
	}

	.chart-custom-legend .legend-items {
		gap: 6px 10px;
	}

	.chart-custom-legend .legend-item {
		font-size: 12px;
		gap: 4px;
	}

	.chart-custom-legend .legend-item-host,
	.chart-custom-legend .legend-item-comparison {
		padding: 3px 6px;
	}

	.chart-custom-legend .legend-color {
		width: 10px;
		height: 10px;
	}

	.chart-custom-legend .legend-add-compare {
		padding: 3px 5px;
	}

	.page-compare-wrapper {
		gap: 8px;
	}

	.page-compare-trigger {
		gap: 6px 8px;
	}

	.page-compare-btn {
		padding: 6px 10px;
		font-size: 13px;
	}

	.page-compare-pills {
		gap: 6px;
	}

	.page-compare-pill {
		padding: 4px 8px;
		font-size: 12px;
	}

	.page-compare-dropdown {
		width: 260px;
		left: 0;
		transform: none;
	}
}

/* Mobile */
@media (max-width: 480px) {
	.chart-custom-legend .legend-items {
		gap: 4px 8px;
	}

	.chart-custom-legend .legend-item {
		font-size: 11px;
	}

	.chart-custom-legend .legend-label {
		max-width: 140px;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	.page-compare-btn {
		padding: 5px 8px;
		font-size: 12px;
	}

	.page-compare-label {
		display: none;
		/* Hide "Compare" text on very small screens */
	}

	.page-compare-pill {
		padding: 3px 6px;
		font-size: 11px;
	}

	.page-compare-pill-name {
		max-width: 80px;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	.page-compare-dropdown {
		width: calc(100vw - 32px);
		max-width: 300px;
	}
}