/**
 * CMG Stock Ticker — styles
 * CSS custom properties (--cmg-ticker-bg, --cmg-ticker-fg, --cmg-ticker-speed)
 * are set via wp_add_inline_style from the plugin based on admin settings.
 */

/* -----------------------------------------------------------------------
   Bar wrapper
----------------------------------------------------------------------- */
#cmg-stock-ticker {
	position: sticky;
	top: 0;
	z-index: 1001;
	width: 100%;
	overflow: hidden;
	background-color: var(--cmg-ticker-bg, #1a1a1a);
	color: var(--cmg-ticker-fg, #ffffff);
	font-family: inherit;
	font-size: 0.75rem;
	line-height: 1;
	height: 36px;
	display: flex;
	align-items: center;
	--cmg-ticker-height: 36px; /* JS overrides this on :root after measuring */
}

/* Empty state — space reserved, bar invisible. Prevents layout shift when
   the cache is cold (background refresh not yet complete). */
#cmg-stock-ticker.cmg-ticker-empty {
	visibility: hidden;
}

/* -----------------------------------------------------------------------
   Scrolling track — two copies of the list for seamless loop
----------------------------------------------------------------------- */
.cmg-ticker-track {
	display: flex;
	flex-wrap: nowrap;
	white-space: nowrap;
	will-change: transform;
	animation: cmg-ticker-scroll var(--cmg-ticker-speed, 60s) linear infinite;
}

/* Pause on hover or keyboard focus within the bar */
#cmg-stock-ticker:hover .cmg-ticker-track,
#cmg-stock-ticker:focus-within .cmg-ticker-track {
	animation-play-state: paused;
}

/* -----------------------------------------------------------------------
   List and items
----------------------------------------------------------------------- */
.cmg-ticker-list {
	display: flex;
	flex-wrap: nowrap;
	list-style: none;
	margin: 0;
	padding: 0;
	align-items: center;
}

.cmg-ticker-item {
	display: inline-flex;
	align-items: center;
	gap: 0.35em;
	padding: 0 1.25em;
	border-right: 1px solid rgba(255, 255, 255, 0.15);
}

.cmg-ticker-item:last-child {
	border-right: none;
}

.cmg-ticker-symbol {
	font-weight: 700;
	letter-spacing: 0.04em;
}

.cmg-ticker-price {
	opacity: 0.9;
}

.cmg-ticker-change {
	font-size: 0.7rem;
}

.cmg-ticker-up   { color: #4caf50; }
.cmg-ticker-down { color: #f44336; }
.cmg-ticker-flat { opacity: 0.6; }

/* -----------------------------------------------------------------------
   Scroll animation
   Track = 2× list width. Moving -50% aligns perfectly with the start
   of the second copy, creating a seamless loop.
----------------------------------------------------------------------- */
@keyframes cmg-ticker-scroll {
	0%   { transform: translateX(0); }
	100% { transform: translateX(-50%); }
}

/* -----------------------------------------------------------------------
   Accessible static list — visually hidden, readable by screen readers
----------------------------------------------------------------------- */
.cmg-ticker-accessible {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
	list-style: none;
}

/* -----------------------------------------------------------------------
   Reduced motion — stop animation, display items in a static scrollable row
----------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
	.cmg-ticker-track {
		animation: none;
		will-change: auto;
	}

	/* Hide the duplicate list; it is only needed for the seamless animation loop */
	.cmg-ticker-duplicate {
		display: none;
	}

	/* Show items in a static overflowing row */
	.cmg-ticker-list {
		overflow-x: auto;
		scrollbar-width: none;
	}

	.cmg-ticker-list::-webkit-scrollbar {
		display: none;
	}
}
