/**
 * CryptoFrame Crypto Markets — core frontend styles.
 *
 * Built on the CryptoFrame design tokens (--cfx-*) with a fallback for every
 * one of them, so the plugin looks correct under the theme and still looks
 * deliberate under any other theme. Nothing here sets a font family or a page
 * background: those belong to the theme, and overriding them is how a plugin
 * ends up looking bolted on.
 *
 * Class namespace: .cfxcm-
 */

/* -------------------------------------------------------------------------
 * Tokens
 * ---------------------------------------------------------------------- */

.cfxcm {
	--cfxcm-up: var(--cfx-market-up, #16a34a);
	--cfxcm-down: var(--cfx-market-down, #dc2626);
	--cfxcm-flat: var(--cfx-text-muted, #6b7280);

	--cfxcm-surface: var(--cfx-surface, #ffffff);
	--cfxcm-surface-alt: var(--cfx-surface-alt, #f6f7f9);
	--cfxcm-border: var(--cfx-border, rgba(0, 0, 0, 0.1));
	--cfxcm-text: var(--cfx-text, inherit);
	--cfxcm-muted: var(--cfx-text-muted, #6b7280);
	--cfxcm-accent: rgb(var(--cfx-primary-rgb, 37 99 235));

	--cfxcm-radius: var(--cfx-radius-md, 10px);
	--cfxcm-radius-sm: var(--cfx-radius-sm, 6px);
	--cfxcm-shadow: var(--cfx-shadow-sm, 0 1px 2px rgba(0, 0, 0, 0.06));
	--cfxcm-gap: 1rem;

	color: var(--cfxcm-text);
	max-width: 100%;
	box-sizing: border-box;
}

.cfxcm *,
.cfxcm *::before,
.cfxcm *::after {
	box-sizing: inherit;
}

/* Dark schemes: the theme flips its own tokens, so the plugin only needs to
   handle the case where a theme sets a colour scheme without CryptoFrame's
   token set present. */
@media (prefers-color-scheme: dark) {
	.cfxcm {
		--cfxcm-surface: var(--cfx-surface, #16181d);
		--cfxcm-surface-alt: var(--cfx-surface-alt, #1e2127);
		--cfxcm-border: var(--cfx-border, rgba(255, 255, 255, 0.12));
		--cfxcm-muted: var(--cfx-text-muted, #9ca3af);
	}
}

/* -------------------------------------------------------------------------
 * Card shell
 * ---------------------------------------------------------------------- */

.cfxcm-card {
	background: var(--cfxcm-surface);
	border: 1px solid var(--cfxcm-border);
	border-radius: var(--cfxcm-radius);
	box-shadow: var(--cfxcm-shadow);
	padding: var(--cfxcm-gap);
}

.cfxcm-card + .cfxcm-card {
	margin-top: var(--cfxcm-gap);
}

.cfxcm__header {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 0.75rem;
	flex-wrap: wrap;
	margin-bottom: 0.75rem;
}

.cfxcm__title {
	margin: 0;
	font-size: var(--cfx-fs-lg, 1.125rem);
	line-height: 1.3;
}

.cfxcm__body > *:last-child {
	margin-bottom: 0;
}

.cfxcm.is-compact {
	--cfxcm-gap: 0.75rem;
	font-size: var(--cfx-fs-sm, 0.9375rem);
}

/* -------------------------------------------------------------------------
 * Freshness and notices
 * ---------------------------------------------------------------------- */

.cfxcm-freshness {
	margin: 0.5rem 0 0;
	font-size: var(--cfx-fs-xs, 0.8125rem);
	color: var(--cfxcm-muted);
}

.cfxcm-freshness--stale {
	color: var(--cfxcm-down);
}

.cfxcm-note,
.cfxcm-disclaimer {
	margin: 0.75rem 0 0;
	font-size: var(--cfx-fs-xs, 0.8125rem);
	color: var(--cfxcm-muted);
}

.cfxcm-attribution {
	margin: 1.5rem 0 0;
	font-size: 0.8125rem;
	text-align: center;
	color: var(--cfx-text-muted, #6b7280);
}

.cfxcm-state {
	padding: 1.25rem;
	text-align: center;
	border: 1px dashed var(--cfxcm-border);
	border-radius: var(--cfxcm-radius-sm);
	color: var(--cfxcm-muted);
}

.cfxcm-state__message {
	margin: 0;
}

.cfxcm-state--error {
	border-style: solid;
	border-color: color-mix(in srgb, var(--cfxcm-down) 40%, transparent);
}

.cfxcm-state__diagnostic {
	margin: 0.5rem 0 0;
	font-size: 0.8125rem;
	font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
	word-break: break-word;
}

/* -------------------------------------------------------------------------
 * Price and change
 * ---------------------------------------------------------------------- */

.cfxcm-quote {
	display: flex;
	align-items: baseline;
	gap: 0.5rem;
	flex-wrap: wrap;
}

.cfxcm-price {
	font-size: var(--cfx-fs-xl, 1.5rem);
	font-weight: 700;
	font-variant-numeric: tabular-nums;
	line-height: 1.2;
}

.cfxcm-change {
	display: inline-flex;
	align-items: center;
	gap: 0.2em;
	font-variant-numeric: tabular-nums;
	font-weight: 600;
	white-space: nowrap;
}

/* Direction is carried by the glyph and the sign as well as the colour, so the
   information survives for anyone who cannot distinguish red from green. */
.cfxcm-change--up {
	color: var(--cfxcm-up);
}

.cfxcm-change--down {
	color: var(--cfxcm-down);
}

.cfxcm-change--flat {
	color: var(--cfxcm-flat);
}

.cfxcm-change__glyph {
	font-size: 0.85em;
}

.cfxcm-stat-inline {
	font-variant-numeric: tabular-nums;
	font-weight: 600;
	white-space: nowrap;
}

/* -------------------------------------------------------------------------
 * Asset labels
 * ---------------------------------------------------------------------- */

.cfxcm-asset {
	display: inline-flex;
	align-items: center;
	gap: 0.5rem;
	min-width: 0;
	text-decoration: none;
	color: inherit;
}

.cfxcm-asset__logo {
	width: 24px;
	height: 24px;
	border-radius: 50%;
	flex: 0 0 auto;
}

.cfxcm-asset__name {
	font-weight: 600;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.cfxcm-asset__symbol {
	color: var(--cfxcm-muted);
	font-size: 0.875em;
	text-transform: uppercase;
	letter-spacing: 0.02em;
}

a.cfxcm-asset:hover .cfxcm-asset__name,
a.cfxcm-asset:focus-visible .cfxcm-asset__name {
	color: var(--cfxcm-accent);
	text-decoration: underline;
}

.cfxcm-badge {
	display: inline-block;
	padding: 0.1em 0.5em;
	border-radius: 999px;
	background: var(--cfxcm-surface-alt);
	color: var(--cfxcm-muted);
	font-size: 0.75rem;
	font-weight: 600;
}

/* -------------------------------------------------------------------------
 * Stats
 * ---------------------------------------------------------------------- */

.cfxcm-stats {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
	gap: var(--cfxcm-gap);
	margin: 0;
}

.cfxcm-stat {
	margin: 0;
}

.cfxcm-stat__label {
	display: block;
	font-size: var(--cfx-fs-xs, 0.8125rem);
	color: var(--cfxcm-muted);
	margin-bottom: 0.15rem;
}

.cfxcm-stat__value {
	display: block;
	margin: 0;
	font-size: var(--cfx-fs-lg, 1.125rem);
	font-weight: 700;
	font-variant-numeric: tabular-nums;
}

.cfxcm-stats-grid {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
	gap: 0.5rem 1.5rem;
	margin: 0;
}

.cfxcm-stats-grid__row {
	display: flex;
	justify-content: space-between;
	gap: 1rem;
	padding: 0.4rem 0;
	border-bottom: 1px solid var(--cfxcm-border);
}

.cfxcm-stats-grid dt {
	color: var(--cfxcm-muted);
	font-size: var(--cfx-fs-sm, 0.9375rem);
}

.cfxcm-stats-grid dd {
	margin: 0;
	font-weight: 600;
	font-variant-numeric: tabular-nums;
	text-align: right;
}

/* -------------------------------------------------------------------------
 * Lists
 * ---------------------------------------------------------------------- */

.cfxcm-list {
	list-style: none;
	margin: 0;
	padding: 0;
}

.cfxcm-list__item {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.75rem;
	padding: 0.6rem 0;
	border-bottom: 1px solid var(--cfxcm-border);
}

.cfxcm-list__item:last-child {
	border-bottom: 0;
}

.cfxcm-list--trending .cfxcm-list__item {
	justify-content: flex-start;
}

.cfxcm-list__position {
	flex: 0 0 1.5rem;
	color: var(--cfxcm-muted);
	font-variant-numeric: tabular-nums;
	font-weight: 700;
}

.cfxcm-list__main {
	min-width: 0;
	flex: 1 1 auto;
}

.cfxcm-list__figures {
	display: flex;
	flex-direction: column;
	align-items: flex-end;
	gap: 0.1rem;
	white-space: nowrap;
}

.cfxcm-list__figures .cfxcm-price {
	font-size: var(--cfx-fs-base, 1rem);
}

.cfxcm-list__meta {
	margin-left: auto;
	color: var(--cfxcm-muted);
	font-size: var(--cfx-fs-xs, 0.8125rem);
}

.cfxcm-list.is-compact .cfxcm-list__item {
	padding: 0.4rem 0;
}

/* -------------------------------------------------------------------------
 * Sparkline
 * ---------------------------------------------------------------------- */

.cfxcm-sparkline {
	display: block;
	width: 100%;
	max-width: 120px;
	height: 32px;
	overflow: visible;
}

.cfxcm-sparkline__path {
	fill: none;
	stroke-width: 1.5;
	stroke-linecap: round;
	stroke-linejoin: round;
	vector-effect: non-scaling-stroke;
}

.cfxcm-sparkline--up .cfxcm-sparkline__path {
	stroke: var(--cfxcm-up);
}

.cfxcm-sparkline--down .cfxcm-sparkline__path {
	stroke: var(--cfxcm-down);
}

.cfxcm-sparkline--flat .cfxcm-sparkline__path {
	stroke: var(--cfxcm-flat);
}

/* -------------------------------------------------------------------------
 * Form controls
 * ---------------------------------------------------------------------- */

.cfxcm-input,
.cfxcm-select {
	width: 100%;
	padding: 0.5rem 0.6rem;
	border: 1px solid var(--cfxcm-border);
	border-radius: var(--cfxcm-radius-sm);
	background: var(--cfxcm-surface);
	color: inherit;
	font: inherit;
	line-height: 1.4;
}

.cfxcm-input:focus-visible,
.cfxcm-select:focus-visible,
.cfxcm-button:focus-visible,
.cfxcm-chip:focus-visible {
	outline: 2px solid var(--cfxcm-accent);
	outline-offset: 2px;
}

.cfxcm-field {
	flex: 1 1 8rem;
	min-width: 0;
}

.cfxcm-field__label {
	display: block;
	margin-bottom: 0.25rem;
	font-size: var(--cfx-fs-xs, 0.8125rem);
	color: var(--cfxcm-muted);
}

.cfxcm-button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 0.4rem;
	padding: 0.5rem 1rem;
	border: 1px solid transparent;
	border-radius: var(--cfxcm-radius-sm);
	background: var(--cfxcm-accent);
	color: #fff;
	font: inherit;
	font-weight: 600;
	cursor: pointer;
}

.cfxcm-button:hover {
	filter: brightness(1.08);
}

.cfxcm-button[disabled] {
	opacity: 0.6;
	cursor: not-allowed;
}

.cfxcm-button--ghost {
	background: transparent;
	border-color: var(--cfxcm-border);
	color: inherit;
}

.cfxcm-chip {
	padding: 0.25rem 0.6rem;
	border: 1px solid var(--cfxcm-border);
	border-radius: 999px;
	background: transparent;
	color: inherit;
	font: inherit;
	font-size: var(--cfx-fs-xs, 0.8125rem);
	font-weight: 600;
	cursor: pointer;
}

.cfxcm-chip.is-active {
	background: var(--cfxcm-accent);
	border-color: var(--cfxcm-accent);
	color: #fff;
}

/* -------------------------------------------------------------------------
 * Skeletons
 * ---------------------------------------------------------------------- */

.cfxcm-skeleton {
	background: linear-gradient(
		90deg,
		var(--cfxcm-surface-alt) 25%,
		color-mix(in srgb, var(--cfxcm-surface-alt) 60%, transparent) 50%,
		var(--cfxcm-surface-alt) 75%
	);
	background-size: 200% 100%;
	border-radius: var(--cfxcm-radius-sm);
	animation: cfxcm-shimmer 1.4s linear infinite;
}

.cfxcm-skeleton--line {
	height: 0.9rem;
	margin-bottom: 0.5rem;
}

.cfxcm-skeleton--chart {
	height: 100%;
	min-height: 160px;
	width: 100%;
}

@keyframes cfxcm-shimmer {
	from {
		background-position: 200% 0;
	}
	to {
		background-position: -200% 0;
	}
}

/* -------------------------------------------------------------------------
 * Screen reader text
 *
 * Themes normally provide this, but the plugin cannot assume it: several
 * accessible labels here would become visible text without it.
 * ---------------------------------------------------------------------- */

.cfxcm .screen-reader-text {
	position: absolute !important;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

/* -------------------------------------------------------------------------
 * Motion
 * ---------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
	.cfxcm *,
	.cfxcm *::before,
	.cfxcm *::after {
		animation-duration: 0.001ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.001ms !important;
	}
}

.cfxcm-no-motion .cfxcm *,
.cfxcm-no-motion .cfxcm *::before,
.cfxcm-no-motion .cfxcm *::after {
	animation: none !important;
	transition: none !important;
}

/* -------------------------------------------------------------------------
 * Automatic internal links
 *
 * Styled as a normal link, because that is what it is. An automatic link that
 * looks different from an author's own links tells the reader something about
 * the site's plumbing rather than about the destination, and a dotted underline
 * is widely read as "definition", which this is not.
 * ---------------------------------------------------------------------- */

.cfxcm-autolink {
	color: inherit;
	text-decoration: underline;
	text-underline-offset: 0.15em;
	text-decoration-thickness: from-font;
}

.cfxcm-autolink:hover,
.cfxcm-autolink:focus-visible {
	color: rgb(var(--cfx-primary-rgb, 37 99 235));
}

/* -------------------------------------------------------------------------
 * Container width
 *
 * The plugin owns `--cfxcm-container` rather than reading the theme's
 * `--cfx-container` directly. Two reasons.
 *
 * First, it is settable: the width comes from a plugin setting, printed as an
 * inline custom property, so a site owner can change it without editing CSS.
 *
 * Second, a theme token is a moving target. CryptoFrame publishes 1200px, but
 * a child theme or a page template can redefine it, and the asset page would
 * then silently follow whatever it became. A plugin-owned token means the
 * width the setting says is the width that renders.
 *
 * These rules live in frontend.css, not asset-page.css, because asset-page.css
 * is enqueued late — after wp_head has printed — and structural layout must not
 * depend on late CSS surviving an optimisation plugin.
 * ---------------------------------------------------------------------- */

.cfxcm-asset-page,
.cfxcm-asset-main__inner {
	width: 100%;
	max-width: var(--cfxcm-container, 1200px);
	margin-left: auto;
	margin-right: auto;
}

.cfxcm-asset-main__inner {
	padding: 2rem 1rem;
}

/* Nested inside the standalone wrapper the constraint is already applied, so
   the module must not add a second one on top of it. */
.cfxcm-asset-main__inner .cfxcm-asset-page {
	max-width: none;
}

/* Nothing inside the page may push the document wider than the viewport. A
   single overflowing table or chart produces a horizontal scrollbar and makes
   a correctly constrained container look broken. */
.cfxcm-asset-page > * {
	max-width: 100%;
}
