/**
 * CryptoStack Donations — inline widget styles (front end) + a few admin tweaks.
 *
 * No external dependencies, no web fonts. Everything is scoped under .csdon-* so it
 * won't leak into the host theme. Light / dark / auto via data-theme on the
 * widget element. The donation form renders inline inside the widget — there is
 * no popup/overlay (the wallet's own modal handles connection).
 */

/* ------------------------------------------------------------------ *
 * Design tokens (light defaults).
 * ------------------------------------------------------------------ */
.csdon-widget {
	--csdon-bg: #ffffff;
	--csdon-fg: #0f172a;
	--csdon-muted: #64748b;
	--csdon-border: #e4e7ef;
	--csdon-field-bg: #f7f8fc;
	--csdon-accent: #6d28d9;
	--csdon-accent-2: #8b5cf6;
	--csdon-accent-fg: #ffffff;
	--csdon-ok: #15803d;
	--csdon-ok-bg: #f0fdf4;
	--csdon-err: #b91c1c;
	--csdon-err-bg: #fef2f2;
	--csdon-ok-dot: #22c55e;
	--csdon-radius: 14px;
	--csdon-radius-sm: 10px;
	--csdon-shadow: 0 6px 24px rgba(15, 23, 42, 0.08);

	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	line-height: 1.5;
	color: var(--csdon-fg);
	max-width: 380px;
	box-sizing: border-box;
}

.csdon-widget *,
.csdon-widget *::before,
.csdon-widget *::after {
	box-sizing: border-box;
}

.csdon-widget[data-theme="dark"] {
	--csdon-bg: #161f33;
	--csdon-fg: #eef2f9;
	--csdon-muted: #a6b4cd;
	--csdon-border: #2c3a57;
	--csdon-field-bg: #1f2c46;
	--csdon-accent: #8b5cf6;
	--csdon-accent-2: #a78bfa;
	--csdon-accent-fg: #ffffff;
	--csdon-ok: #4ade80;
	--csdon-ok-bg: #07291a;
	--csdon-err: #fca5a5;
	--csdon-err-bg: #2f1212;
	--csdon-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
}

@media (prefers-color-scheme: dark) {
	.csdon-widget[data-theme="auto"] {
		--csdon-bg: #161f33;
		--csdon-fg: #eef2f9;
		--csdon-muted: #a6b4cd;
		--csdon-border: #2c3a57;
		--csdon-field-bg: #1f2c46;
		--csdon-accent: #8b5cf6;
		--csdon-accent-2: #a78bfa;
		--csdon-accent-fg: #ffffff;
		--csdon-ok: #4ade80;
		--csdon-ok-bg: #07291a;
		--csdon-err: #fca5a5;
		--csdon-err-bg: #2f1212;
		--csdon-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
	}
}

/* ------------------------------------------------------------------ *
 * Card.
 * ------------------------------------------------------------------ */
.csdon-card {
	background: var(--csdon-bg);
	border: 1px solid var(--csdon-border);
	border-radius: var(--csdon-radius);
	box-shadow: var(--csdon-shadow);
	padding: 18px;
	display: flex;
	flex-direction: column;
	gap: 14px;
}

/* Network + asset sit side by side; a hidden one lets the other fill the row. */
.csdon-grid {
	display: flex;
	flex-wrap: wrap;
	gap: 12px;
}

.csdon-grid > .csdon-field {
	flex: 1 1 140px;
	min-width: 0;
}

/* ------------------------------------------------------------------ *
 * Fields.
 * ------------------------------------------------------------------ */
.csdon-field {
	display: flex;
	flex-direction: column;
	gap: 6px;
	margin: 0;
}

.csdon-label {
	font-size: 12px;
	font-weight: 600;
	letter-spacing: 0.01em;
	text-transform: uppercase;
	color: var(--csdon-muted);
}

.csdon-select,
.csdon-input {
	width: 100%;
	height: 44px;
	padding: 0 12px;
	font-size: 15px;
	color: var(--csdon-fg);
	background: var(--csdon-field-bg);
	border: 1px solid var(--csdon-border);
	border-radius: var(--csdon-radius-sm);
	appearance: none;
	-webkit-appearance: none;
	transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.csdon-select {
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2364748b' d='M6 8 0 2l1.4-1.4L6 5.2 10.6.6 12 2z'/%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-position: right 12px center;
	padding-right: 32px;
	cursor: pointer;
}

.csdon-input::placeholder {
	color: var(--csdon-muted);
	opacity: 1;
}

.csdon-select:focus,
.csdon-input:focus {
	outline: none;
	border-color: var(--csdon-accent);
	box-shadow: 0 0 0 3px color-mix(in srgb, var(--csdon-accent) 22%, transparent);
}

/* ------------------------------------------------------------------ *
 * Wallet connect/disconnect button (full width; reflects state).
 * ------------------------------------------------------------------ */
.csdon-wallet-btn {
	width: 100%;
	height: 44px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	padding: 0 14px;
	font-size: 14px;
	font-weight: 600;
	color: var(--csdon-accent);
	background: transparent;
	border: 1px solid color-mix(in srgb, var(--csdon-accent) 45%, transparent);
	border-radius: var(--csdon-radius-sm);
	cursor: pointer;
	transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.csdon-wallet-btn:hover {
	background: color-mix(in srgb, var(--csdon-accent) 10%, transparent);
}

.csdon-wallet-btn[data-connected="true"] {
	color: var(--csdon-fg);
	border-color: var(--csdon-border);
	background: color-mix(in srgb, var(--csdon-ok-dot) 8%, transparent);
}

.csdon-wallet-btn[data-connected="true"]::before {
	content: "";
	flex: 0 0 auto;
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: var(--csdon-ok-dot);
	box-shadow: 0 0 0 3px color-mix(in srgb, var(--csdon-ok-dot) 25%, transparent);
}

/* ------------------------------------------------------------------ *
 * Donate button.
 * ------------------------------------------------------------------ */
.csdon-donate-btn {
	width: 100%;
	height: 48px;
	font-size: 16px;
	font-weight: 700;
	color: var(--csdon-accent-fg);
	background: linear-gradient(135deg, var(--csdon-accent), var(--csdon-accent-2));
	border: 0;
	border-radius: var(--csdon-radius-sm);
	cursor: pointer;
	transition: filter 0.15s ease, transform 0.05s ease, box-shadow 0.15s ease;
	box-shadow: 0 4px 14px color-mix(in srgb, var(--csdon-accent) 35%, transparent);
}

.csdon-donate-btn:hover {
	filter: brightness(1.06);
}

.csdon-donate-btn:active {
	transform: translateY(1px);
}

.csdon-donate-btn:disabled {
	opacity: 0.65;
	cursor: progress;
	box-shadow: none;
}

/* ------------------------------------------------------------------ *
 * Status + notes.
 * ------------------------------------------------------------------ */
.csdon-status {
	font-size: 14px;
	min-height: 0;
}

.csdon-status:empty {
	display: none;
}

.csdon-status--busy {
	color: var(--csdon-muted);
}

.csdon-status--ok {
	padding: 10px 12px;
	border-radius: var(--csdon-radius-sm);
	color: var(--csdon-ok);
	background: var(--csdon-ok-bg);
}

.csdon-status--err {
	padding: 10px 12px;
	border-radius: var(--csdon-radius-sm);
	color: var(--csdon-err);
	background: var(--csdon-err-bg);
}

.csdon-txlink {
	color: inherit;
	font-weight: 700;
	text-decoration: underline;
}

.csdon-hint {
	margin: 6px 0 0;
	font-size: 12px;
	color: var(--csdon-muted);
}

.csdon-fee-note {
	margin: 0;
	font-size: 12px;
	color: var(--csdon-muted);
	text-align: center;
}

/* Admin-only placeholder when nothing is configured yet. */
.csdon-empty {
	padding: 12px 14px;
	font-size: 13px;
	color: var(--csdon-muted);
	border: 1px dashed var(--csdon-border);
	border-radius: var(--csdon-radius);
	background: transparent;
}

/* ------------------------------------------------------------------ *
 * Loading skeleton (shown before JS swaps in the live form).
 * ------------------------------------------------------------------ */
.csdon-skeleton {
	border-radius: var(--csdon-radius-sm);
	background: linear-gradient(
		90deg,
		color-mix(in srgb, var(--csdon-muted) 12%, transparent) 25%,
		color-mix(in srgb, var(--csdon-muted) 20%, transparent) 37%,
		color-mix(in srgb, var(--csdon-muted) 12%, transparent) 63%
	);
	background-size: 400% 100%;
	animation: csdon-shimmer 1.4s ease infinite;
}

.csdon-skeleton--row {
	height: 44px;
}

.csdon-skeleton--input {
	height: 44px;
}

@keyframes csdon-shimmer {
	0% { background-position: 100% 0; }
	100% { background-position: 0 0; }
}

@media (prefers-reduced-motion: reduce) {
	.csdon-skeleton {
		animation: none;
	}
}

/* ------------------------------------------------------------------ *
 * Admin settings page tweaks (loaded only on our settings screen).
 * ------------------------------------------------------------------ */
.csdon-settings .csdon-lock-hint {
	margin: 8px 0 0;
	padding: 8px 12px;
	border-left: 3px solid #2271b1;
	background: #f0f6fc;
	font-size: 13px;
}

.csdon-settings input.code.csdon-invalid {
	border-color: #d63638;
	box-shadow: 0 0 0 1px #d63638;
}

.csdon-settings .csdon-field-warning {
	display: block;
	margin-top: 4px;
	color: #d63638;
	font-size: 12px;
}

/* ------------------------------------------------------------------ *
 * USD amount adornment + live crypto estimate.
 * Donors enter USD (shown with a "$" prefix); the estimate line shows
 * the approximate crypto amount that will actually be sent.
 * ------------------------------------------------------------------ */
.csdon-amount-wrap {
	position: relative;
}

.csdon-amount-wrap .csdon-amount-unit {
	position: absolute;
	right: 12px;
	top: 50%;
	transform: translateY(-50%);
	font-size: 13px;
	font-weight: 600;
	color: var(--csdon-muted);
	pointer-events: none;
	text-transform: uppercase;
	letter-spacing: 0.02em;
}

.csdon-amount-wrap .csdon-input {
	/* Leave room for the asset unit suffix (e.g. "BTC"). */
	padding-right: 60px;
}

.csdon-estimate {
	min-height: 16px;
	margin-top: 6px;
	font-size: 12px;
	line-height: 1.4;
	color: var(--csdon-muted);
}

.csdon-estimate--busy {
	opacity: 0.8;
}

.csdon-estimate--ok {
	color: var(--csdon-accent);
}

.csdon-estimate--err {
	color: #dc2626;
}

/* ================================================================== *
 * Dark-theme legibility hardening.
 *
 * Some host themes inject their own color onto inputs, selects and
 * buttons with high specificity, which can force near-black text onto
 * the dark card (AMOUNT field, CONNECT WALLET, DONATE). Native <option>
 * lists also fall back to the OS/browser default (dark-on-dark) because
 * the open dropdown is painted outside the widget's styles.
 *
 * The rules below re-assert the widget's own colors with enough weight
 * to win, and explicitly color the option list. Scoped under .csdon-widget
 * so nothing leaks into the host theme.
 * ================================================================== */

/* Inputs & selects: force the widget foreground, beating theme bleed. */
.csdon-widget .csdon-input,
.csdon-widget .csdon-select,
.csdon-widget input.csdon-input,
.csdon-widget select.csdon-select {
	color: var(--csdon-fg) !important;
	background-color: var(--csdon-field-bg) !important;
	-webkit-text-fill-color: var(--csdon-fg); /* Safari/iOS honors this over color. */
	opacity: 1;
}

/* The amount input specifically (it sits inside .csdon-amount-wrap). */
.csdon-widget .csdon-amount-wrap .csdon-input {
	color: var(--csdon-fg) !important;
	-webkit-text-fill-color: var(--csdon-fg);
}

/* The asset unit suffix (e.g. "BTC") after the amount. */
.csdon-widget .csdon-amount-unit {
	color: var(--csdon-fg);
	-webkit-text-fill-color: var(--csdon-fg);
	opacity: 0.9;
}

/* Placeholder stays muted but visible in both themes. */
.csdon-widget .csdon-input::placeholder {
	color: var(--csdon-muted) !important;
	-webkit-text-fill-color: var(--csdon-muted);
	opacity: 1;
}

/* Native <option> list: the open dropdown is painted by the OS, so give
 * it explicit colors or it defaults to dark-on-dark. Setting these on the
 * select cascades to its options in most browsers; the option rules make
 * it explicit for the rest. */
.csdon-widget .csdon-select option,
.csdon-widget .csdon-select optgroup {
	color: var(--csdon-fg);
	background-color: var(--csdon-bg);
}

/* Dark theme (explicit): make the option list unmistakably light text on
 * a dark surface, matching the card. Covers data-theme="dark" and the
 * auto theme under a dark OS preference. */
.csdon-widget[data-theme="dark"] .csdon-select option,
.csdon-widget[data-theme="dark"] .csdon-select optgroup {
	color: #eef2f9;
	background-color: #1f2c46;
}

@media (prefers-color-scheme: dark) {
	.csdon-widget[data-theme="auto"] .csdon-select option,
	.csdon-widget[data-theme="auto"] .csdon-select optgroup {
		color: #eef2f9;
		background-color: #1f2c46;
	}
}

/* Wallet button: keep the accent-colored label readable and immune to
 * theme text-color bleed. */
.csdon-widget .csdon-wallet-btn {
	color: var(--csdon-accent) !important;
	-webkit-text-fill-color: var(--csdon-accent);
}

.csdon-widget .csdon-wallet-btn[data-connected="true"] {
	color: var(--csdon-fg) !important;
	-webkit-text-fill-color: var(--csdon-fg);
}

/* Donate button: its label must stay white on the accent gradient even if
 * the host theme sets a dark button text color. */
.csdon-widget .csdon-donate-btn {
	color: var(--csdon-accent-fg) !important;
	-webkit-text-fill-color: var(--csdon-accent-fg);
}

/* The dropdown chevron in the select is drawn as a background SVG in a
 * fixed slate color; brighten it in dark mode so it doesn't vanish. */
.csdon-widget[data-theme="dark"] .csdon-select {
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23a6b4cd' d='M6 8 0 2l1.4-1.4L6 5.2 10.6.6 12 2z'/%3E%3C/svg%3E");
}

@media (prefers-color-scheme: dark) {
	.csdon-widget[data-theme="auto"] .csdon-select {
		background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23a6b4cd' d='M6 8 0 2l1.4-1.4L6 5.2 10.6.6 12 2z'/%3E%3C/svg%3E");
	}
}