/* FMX Buy Calculator. Colors come from the FarmX theme tokens; fallbacks match them. */
@font-face {
	font-family: "IBM Plex Mono";
	font-style: normal;
	font-weight: 400;
	font-display: swap;
	src: url("fonts/ibm-plex-mono-latin-400.woff2") format("woff2");
}

@font-face {
	font-family: "IBM Plex Mono";
	font-style: normal;
	font-weight: 600;
	font-display: swap;
	src: url("fonts/ibm-plex-mono-latin-600.woff2") format("woff2");
}

.fmx-buy {
	--fmx-surface: var(--color-surface, #20272d);
	--fmx-bg: var(--color-bg, #192026);
	--fmx-text: var(--color-text, #e6eaed);
	--fmx-muted: var(--color-muted, #9aa6b0);
	--fmx-gold: var(--color-gold, #d7b65d);
	--fmx-gold-strong: var(--color-gold-strong, #e6c978);
	--fmx-border: var(--color-border, rgb(215 182 93 / 20%));
	--fmx-radius: var(--radius, 16px);
	--fmx-ask: #ef4444;
	--fmx-ask-bg: #2f0f0e;
	--fmx-bid: #20b858;
	--fmx-bid-bg: #051d0e;
	--fmx-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

	max-width: 800px;
	color: var(--fmx-text);
}

.fmx-buy *,
.fmx-buy *::before,
.fmx-buy *::after {
	box-sizing: border-box;
}

.fmx-buy p {
	margin: 0;
}

.fmx-buy__intro {
	margin-bottom: 24px !important;
	color: var(--fmx-muted);
}

/* Option switch */
.fmx-buy__tabs {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 6px;
	margin-bottom: 16px;
	padding: 6px;
	border: 1px solid var(--fmx-border);
	border-radius: var(--fmx-radius);
	background: var(--fmx-surface);
}

.fmx-buy__tab {
	min-height: 44px;
	padding: 8px 12px;
	border: 0;
	border-radius: 12px;
	background: transparent;
	color: var(--fmx-muted);
	font: inherit;
	font-weight: 600;
	cursor: pointer;
	transition: background-color 0.2s, color 0.2s;
}

.fmx-buy__tab:hover {
	color: var(--fmx-text);
}

.fmx-buy__tab[aria-selected="true"] {
	background: var(--fmx-gold);
	color: var(--fmx-bg);
}

.fmx-buy__tab:focus-visible,
.fmx-buy__copy:focus-visible {
	outline: 2px solid var(--fmx-gold-strong);
	outline-offset: 2px;
}

/* Panels */
.fmx-buy__panel {
	margin-bottom: 24px;
	padding: 24px;
	border: 1px solid var(--fmx-border);
	border-radius: var(--fmx-radius);
	background: var(--fmx-surface);
}

.fmx-buy__panel[hidden] {
	display: none;
}

.fmx-buy__lead {
	margin-bottom: 20px !important;
	color: var(--fmx-muted);
}

/* Fields */
.fmx-buy__book {
	display: grid;
	gap: 16px;
	margin-bottom: 20px;
}

.fmx-buy__pair {
	display: grid;
	gap: 16px;
}

.fmx-buy__label {
	display: block;
	margin-bottom: 6px;
	font-size: 0.875rem;
	font-weight: 600;
}

.fmx-buy__label--ask {
	color: var(--fmx-ask);
}

.fmx-buy__label--bid {
	color: var(--fmx-bid);
}

.fmx-buy__input {
	display: block;
	width: 100%;
	min-height: 48px;
	padding: 10px 14px;
	border: 1px solid var(--fmx-border);
	border-radius: 12px;
	background: var(--fmx-bg);
	color: var(--fmx-text);
	font: inherit;
	font-variant-numeric: tabular-nums;
}

.fmx-buy__input::placeholder {
	color: var(--fmx-muted);
	opacity: 0.8;
}

.fmx-buy__input:focus-visible {
	outline: 2px solid var(--fmx-gold-strong);
	outline-offset: 1px;
	border-color: var(--fmx-gold);
}

.fmx-buy__input[aria-invalid="true"] {
	border-color: var(--fmx-ask);
}

.fmx-buy__input--result {
	border-color: var(--fmx-gold);
	font-weight: 700;
}

.fmx-buy__sr-input {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	border: 0;
}

.fmx-buy__shown {
	display: flex;
	align-items: center;
	flex: 1 1 auto;
	min-width: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.fmx-buy__input--mono {
	font-family: var(--fmx-mono);
	font-size: 0.875rem;
	padding-inline: 10px;
}

.fmx-buy__result {
	display: flex;
	gap: 8px;
}

.fmx-buy__copy {
	flex: none;
	min-width: 84px;
	min-height: 48px;
	padding: 0 16px;
	border: 1px solid var(--fmx-gold);
	border-radius: 12px;
	background: transparent;
	color: var(--fmx-gold);
	font: inherit;
	font-weight: 600;
	cursor: pointer;
	transition: background-color 0.2s, color 0.2s;
}

.fmx-buy__copy:hover:not(:disabled) {
	background: var(--fmx-gold);
	color: var(--fmx-bg);
}

.fmx-buy__copy:disabled {
	opacity: 0.4;
	cursor: not-allowed;
}

.fmx-buy__error {
	margin-top: 6px !important;
	color: var(--fmx-ask);
	font-size: 0.875rem;
}

.fmx-buy__error[hidden],
.fmx-buy__msg[hidden],
.fmx-buy__age[hidden],
.fmx-buy__facts[hidden] {
	display: none;
}

/* Results and messages */
.fmx-buy__facts {
	display: grid;
	gap: 8px;
	margin: 20px 0 0;
	padding-top: 16px;
	border-top: 1px solid var(--fmx-border);
}

.fmx-buy__fact {
	display: flex;
	justify-content: space-between;
	gap: 16px;
}

.fmx-buy__fact dt {
	color: var(--fmx-muted);
}

.fmx-buy__fact dd {
	margin: 0;
	font-weight: 600;
	font-variant-numeric: tabular-nums;
	text-align: right;
}

.fmx-buy__note,
.fmx-buy__msg,
.fmx-buy__age {
	margin-top: 16px !important;
	color: var(--fmx-muted);
	font-size: 0.9375rem;
}

.fmx-buy__msg--warn {
	padding: 12px 14px;
	border: 1px solid var(--fmx-border);
	border-left: 3px solid var(--fmx-gold);
	border-radius: 8px;
	color: var(--fmx-text);
}

/* Link to Dexie */
.fmx-buy__dexie {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px 12px;
	margin: -4px 0 20px !important;
}

.fmx-buy__link {
	color: var(--fmx-gold);
	font-weight: 600;
	text-decoration: underline;
	text-underline-offset: 3px;
}

.fmx-buy__link:hover {
	color: var(--fmx-gold-strong);
}

.fmx-buy__link:focus-visible {
	outline: 2px solid var(--fmx-gold-strong);
	outline-offset: 2px;
}

.fmx-buy__link::after {
	content: " \2197";
}

.fmx-buy__hint {
	color: var(--fmx-muted);
	font-size: 0.8125rem;
}

.fmx-buy .screen-reader-text {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
}

/* How to place the offer */
.fmx-buy__how-title {
	margin: 0 0 12px;
	font-size: 1.125rem;
}

.fmx-buy__steps {
	margin: 0 0 16px;
	padding-left: 1.25em;
	color: var(--fmx-muted);
}

.fmx-buy__steps li + li {
	margin-top: 4px;
}

.fmx-buy__small {
	margin-top: 12px !important;
	color: var(--fmx-muted);
	font-size: 0.8125rem;
}

/* Order book preview ("ladder") */
.fmx-book-wrap {
	margin-bottom: 24px;
}

.fmx-book-wrap[hidden] {
	display: none;
}

.fmx-book-note {
	margin: 0 0 12px !important;
	color: var(--fmx-muted);
	font-size: 0.8125rem;
	line-height: 1.5;
}

.fmx-book-note strong {
	display: block;
	color: var(--fmx-text, inherit);
	font-size: 0.875rem;
}

.fmx-book {
	padding: 8px 0;
	overflow: hidden;
	border: 1px solid var(--fmx-border);
	border-radius: var(--fmx-radius);
	background: #000;
	font-family: var(--fmx-mono);
	font-size: 0.9375rem;
	font-variant-numeric: tabular-nums;
}

.fmx-book[hidden] {
	display: none;
}

.fmx-book__row {
	display: flex;
	align-items: center;
	gap: 8px;
	min-height: 30px;
	padding: 0 14px;
}

/* Stepped bars: decorative depth, no real data. Longer bars are further from the middle. */
.fmx-book__side > :nth-child(1) { --w: 82%; }
.fmx-book__side > :nth-child(2) { --w: 70%; }
.fmx-book__side > :nth-child(3) { --w: 58%; }
.fmx-book__side > :nth-child(4) { --w: 46%; }
.fmx-book__side > :nth-child(5) { --w: 34%; }
.fmx-book__side > :nth-child(6) { --w: 22%; }

.fmx-book__row--ask {
	background: linear-gradient(to left, var(--fmx-ask-bg) var(--w, 12%), transparent var(--w, 12%));
}

.fmx-book__row--bid {
	background: linear-gradient(to left, var(--fmx-bid-bg) var(--w, 12%), transparent var(--w, 12%));
}

/* Bids grow away from the middle, so the order is reversed. */
.fmx-book__side:last-child > :nth-child(1) { --w: 8%; }
.fmx-book__side:last-child > :nth-child(2) { --w: 20%; }
.fmx-book__side:last-child > :nth-child(3) { --w: 34%; }
.fmx-book__side:last-child > :nth-child(4) { --w: 50%; }
.fmx-book__side:last-child > :nth-child(5) { --w: 68%; }
.fmx-book__side:last-child > :nth-child(6) { --w: 86%; }

.fmx-book__row--value.fmx-book__row--ask {
	--w: 14%;
	color: var(--fmx-ask);
}

.fmx-book__row--value.fmx-book__row--bid {
	--w: 8%;
	color: var(--fmx-bid);
}

.fmx-book__mid {
	display: flex;
	align-items: center;
	gap: 12px;
	min-height: 38px;
	padding: 0 14px;
	color: #fff;
}

.fmx-book__line {
	flex: 1;
	height: 1px;
	background: #3446be;
}

.fmx-book__row--mine {
	color: var(--fmx-bid);
	font-weight: 600;
}

.fmx-book__row--mine[hidden] {
	display: none;
}

.fmx-book__tag {
	font-weight: 400;
}

.fmx-book__num.is-empty {
	color: var(--fmx-muted);
	font-family: var(--font-sans, system-ui, sans-serif);
	font-size: 0.8125rem;
	opacity: 0.75;
}

/* Layout: form on the left, ladder on the right (wide screens only). */
@media (min-width: 820px) {
	.fmx-buy {
		display: grid;
		grid-template-columns: minmax(0, 460px) 300px;
		grid-template-areas:
			"intro intro"
			"tabs book"
			"panels book"
			"how .";
		column-gap: 32px;
		align-items: start;
	}

	.fmx-buy__intro {
		grid-area: intro;
		max-width: 620px;
	}

	.fmx-buy__tabs {
		grid-area: tabs;
	}

	.fmx-buy__panels {
		grid-area: panels;
	}

	/* Bottom of the ladder lines up with the bottom of the form frame. */
	.fmx-book-wrap {
		grid-area: book;
		align-self: end;
	}

	.fmx-buy__how {
		grid-area: how;
	}
}

@media (min-width: 640px) {
	.fmx-buy__book {
		grid-template-columns: 1fr 1fr;
	}
}

@media (max-width: 400px) {
	.fmx-buy__panel {
		padding: 16px;
	}

	.fmx-buy__result {
		flex-direction: column;
	}

	.fmx-buy__copy {
		width: 100%;
	}
}

@media (prefers-reduced-motion: reduce) {
	.fmx-buy__tab,
	.fmx-buy__copy {
		transition: none;
	}
}
