/* Sparrow Affiliates — frontend styles
 * Scoped under .spm-aff-widget. All colours overridable via CSS custom properties.
 */

.spm-aff-widget {
	--spm-color-primary: #2c5fff;
	--spm-color-bg-soft: #f9fafb;
	--spm-color-border: #e5e7eb;
	--spm-color-muted: #6b7280;
	--spm-color-text: #111827;
	--spm-radius: 8px;
	color: var(--spm-color-text);
	font-family: inherit;
	box-sizing: border-box;
}

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

/* ── Buttons ───────────────────────────────────────────────────────── */
.spm-aff-btn {
	display: inline-block;
	padding: 10px 18px;
	font-weight: 600;
	font-size: 14px;
	line-height: 1.2;
	color: #fff;
	background: var(--spm-color-primary);
	border: 1px solid var(--spm-color-primary);
	border-radius: var(--spm-radius);
	cursor: pointer;
	text-decoration: none;
	transition: filter 0.15s ease, transform 0.05s ease;
}
.spm-aff-btn:hover { filter: brightness(0.93); }
.spm-aff-btn:active { transform: translateY(1px); }
.spm-aff-btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.spm-aff-btn--ghost {
	color: var(--spm-color-text);
	background: transparent;
	border-color: var(--spm-color-border);
}
.spm-aff-btn--primary {} /* alias */

/* ── Cards & layout ────────────────────────────────────────────────── */
.spm-aff-card {
	padding: 16px 18px;
	background: #fff;
	border: 1px solid var(--spm-color-border);
	border-radius: var(--spm-radius);
	margin-bottom: 16px;
}

.spm-aff-card__label {
	display: block;
	font-size: 12px;
	font-weight: 500;
	color: var(--spm-color-muted);
	text-transform: uppercase;
	letter-spacing: 0.05em;
	margin-bottom: 6px;
}

.spm-aff-empty {
	padding: 24px;
	text-align: center;
	background: var(--spm-color-bg-soft);
	border-radius: var(--spm-radius);
}
.spm-aff-empty--data {
	background: transparent;
	padding: 16px;
	border: 1px dashed var(--spm-color-border, #e5e7eb);
}
.spm-aff-empty--data p:first-child { margin-top: 0; }
.spm-aff-empty--data p:last-child  { margin-bottom: 0; }
.spm-aff-empty--data a { color: inherit; text-decoration: underline; }

/* ── Copy-row ──────────────────────────────────────────────────────── */
.spm-aff-copy-row {
	display: flex;
	gap: 8px;
}
.spm-aff-copy-row input {
	flex: 1 1 auto;
	padding: 8px 10px;
	font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
	font-size: 13px;
	background: var(--spm-color-bg-soft);
	border: 1px solid var(--spm-color-border);
	border-radius: var(--spm-radius);
}

/* ── Stats grid ────────────────────────────────────────────────────── */
.spm-aff-stats {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
	gap: 12px;
	margin-bottom: 16px;
}
.spm-aff-stat {
	padding: 14px 16px;
	background: #fff;
	border: 1px solid var(--spm-color-border);
	border-radius: var(--spm-radius);
}
.spm-aff-stat__label {
	font-size: 12px;
	color: var(--spm-color-muted);
	text-transform: uppercase;
	letter-spacing: 0.04em;
}
.spm-aff-stat__value {
	margin-top: 4px;
	font-size: 22px;
	font-weight: 700;
}

/* ── Forms ─────────────────────────────────────────────────────────── */
.spm-aff-signup__header { margin-bottom: 16px; }
.spm-aff-signup__header h3 { margin: 0 0 4px; font-size: 22px; }
.spm-aff-signup__header p { margin: 0; color: var(--spm-color-muted); }

.spm-aff-field {
	margin-bottom: 12px;
}
.spm-aff-field label {
	display: block;
	margin-bottom: 4px;
	font-size: 13px;
	font-weight: 600;
}
.spm-aff-field input {
	width: 100%;
	padding: 9px 10px;
	font-size: 14px;
	border: 1px solid var(--spm-color-border);
	border-radius: var(--spm-radius);
}
.spm-aff-field input:focus {
	border-color: var(--spm-color-primary);
	outline: 2px solid color-mix(in srgb, var(--spm-color-primary) 25%, transparent);
}

.spm-aff-message {
	margin-top: 12px;
	padding: 10px 12px;
	border-radius: var(--spm-radius);
	font-size: 14px;
}
.spm-aff-message.is-success { background: #dcfce7; color: #166534; }
.spm-aff-message.is-error { background: #fee2e2; color: #991b1b; }

.spm-aff-note { font-size: 13px; color: var(--spm-color-muted); }

/* ── Refer modal ───────────────────────────────────────────────────── */
.spm-aff-modal {
	position: fixed;
	inset: 0;
	background: rgba(0, 0, 0, 0.55);
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 100000;
}
.spm-aff-modal[hidden] { display: none; }
.spm-aff-modal__inner {
	position: relative;
	width: 92%;
	max-width: 480px;
	padding: 24px;
	background: #fff;
	border-radius: var(--spm-radius);
	box-shadow: 0 24px 48px rgba(0, 0, 0, 0.2);
}
.spm-aff-modal__close {
	position: absolute;
	top: 8px;
	right: 12px;
	background: transparent;
	border: 0;
	font-size: 24px;
	line-height: 1;
	cursor: pointer;
	color: var(--spm-color-muted);
}

.spm-aff-share-row {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin-top: 16px;
}
.spm-aff-share {
	flex: 1 1 auto;
	padding: 8px 10px;
	text-align: center;
	background: var(--spm-color-bg-soft);
	border-radius: var(--spm-radius);
	color: var(--spm-color-text);
	text-decoration: none;
	font-size: 13px;
	font-weight: 600;
}

/* ── Banners ───────────────────────────────────────────────────────── */
.spm-aff-banners {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
	gap: 16px;
}
.spm-aff-banner {
	padding: 16px;
	background: #fff;
	border: 1px solid var(--spm-color-border);
	border-radius: var(--spm-radius);
}
.spm-aff-banner__preview img {
	max-width: 100%;
	height: auto;
	display: block;
	margin-bottom: 12px;
}
.spm-aff-banner__embed textarea {
	width: 100%;
	padding: 8px;
	font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
	font-size: 12px;
	border: 1px solid var(--spm-color-border);
	border-radius: var(--spm-radius);
	margin-bottom: 8px;
}

/* ── Payout history table ──────────────────────────────────────────── */
.spm-aff-payouts__balance {
	display: flex;
	align-items: baseline;
	gap: 8px;
	margin-bottom: 12px;
}
.spm-aff-payouts__amount {
	font-size: 28px;
	font-weight: 700;
	color: var(--spm-color-primary);
}
.spm-aff-payouts__label {
	color: var(--spm-color-muted);
}

.spm-aff-table {
	width: 100%;
	border-collapse: collapse;
}
.spm-aff-table th,
.spm-aff-table td {
	padding: 10px 12px;
	text-align: left;
	border-bottom: 1px solid var(--spm-color-border);
	font-size: 14px;
}
.spm-aff-table th {
	background: var(--spm-color-bg-soft);
	font-weight: 600;
	font-size: 12px;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	color: var(--spm-color-muted);
}
.spm-aff-table__amount { text-align: right; font-variant-numeric: tabular-nums; }

.spm-aff-status {
	display: inline-block;
	padding: 2px 8px;
	border-radius: 999px;
	font-size: 11px;
	font-weight: 600;
	text-transform: capitalize;
}
.spm-aff-status--completed,
.spm-aff-status--approved,
.spm-aff-status--paid { background: #dcfce7; color: #166534; }
.spm-aff-status--pending,
.spm-aff-status--processing { background: #fef3c7; color: #92400e; }
.spm-aff-status--failed,
.spm-aff-status--rejected,
.spm-aff-status--cancelled { background: #fee2e2; color: #991b1b; }
.spm-aff-status--unclaimed {
	background: #fed7aa;
	color: #9a3412;
	margin-left: 4px;
	border: 1px solid #fb923c;
}

/* ── Cookie self-test widget ───────────────────────────────────────── */
.spm-aff-cookie-test__intro,
.spm-aff-card__intro {
	margin: 0 0 12px 0;
	color: var(--spm-color-muted, #6b7280);
	font-size: 14px;
}
.spm-aff-cookie-test__status { margin: 12px 0; min-height: 60px; }
.spm-aff-cookie-test__result {
	padding: 12px 14px;
	border-radius: 6px;
	border-left: 3px solid;
}
.spm-aff-cookie-test__result p {
	margin: 6px 0 0 0;
	font-size: 13px;
	line-height: 1.5;
}
.spm-aff-cookie-test__result--ok      { background: #dcfce7; border-left-color: #16a34a; color: #14532d; }
.spm-aff-cookie-test__result--warn    { background: #fef3c7; border-left-color: #f59e0b; color: #92400e; }
.spm-aff-cookie-test__result--neutral { background: #f1f5f9; border-left-color: #64748b; color: #334155; }
.spm-aff-cookie-test__result--error   { background: #fee2e2; border-left-color: #ef4444; color: #7f1d1d; }
.spm-aff-cookie-test__actions {
	display: flex;
	gap: 8px;
	flex-wrap: wrap;
	margin: 12px 0;
}
.spm-aff-cookie-test__help {
	margin-top: 12px;
	font-size: 13px;
}
.spm-aff-cookie-test__help summary {
	cursor: pointer;
	color: var(--spm-color-muted, #6b7280);
	font-weight: 500;
}
.spm-aff-cookie-test__help ul {
	margin-top: 8px;
	padding-left: 20px;
	color: var(--spm-color-muted, #6b7280);
	line-height: 1.6;
}

/* ── Affiliate visibility cloak ────────────────────────────────────
   Applied server-side to elements with affiliate visibility rules. JS
   evaluates conditions against /me and either removes the cloak (reveal)
   or removes the entire element (hide). Using `visibility:hidden` rather
   than `display:none` keeps the layout stable while the decision is
   pending — the element occupies its space without flashing visible. */
.spm-aff-vis-cloak {
	visibility: hidden !important;
}
/* If JS is broken or never runs, we don't want elements stuck cloaked
   forever — auto-reveal after a generous timeout. The :where() selector
   has zero specificity so any operator override wins. */
@media (prefers-reduced-motion: no-preference) {
	:where(.spm-aff-vis-cloak) {
		animation: spm-aff-vis-failsafe-reveal 0s linear 3s forwards;
	}
}
@keyframes spm-aff-vis-failsafe-reveal {
	to { visibility: visible; }
}

/* ── Refer this Product widget ─────────────────────────────────────── */
.spm-aff-refer-product {
	padding: 16px 18px;
	border: 1px solid var(--spm-color-border, #e5e7eb);
	border-radius: 8px;
	background: var(--spm-color-card-bg, #f9fafb);
	margin: 16px 0;
}
.spm-aff-refer-product__heading {
	margin: 0 0 4px 0;
	font-size: 15px;
	font-weight: 600;
}
.spm-aff-refer-product__description {
	margin: 0 0 10px 0;
	font-size: 13px;
	opacity: 0.75;
}
.spm-aff-refer-product .spm-aff-copy-row { margin: 0; }

/* ── Potential Commission widget ────────────────────────────────────
   Renders on product pages showing the visiting affiliate's potential
   commission for the current product. Server renders a placeholder amount
   using the program default rate; JS recomputes per-affiliate via /me.
   Most styling is driven by Elementor controls; CSS just provides the
   cloak behavior and a sane default block. */
.spm-aff-pc {
	background-color: #f9fafb;
	border-radius: 8px;
	padding: 16px 20px;
	text-align: center;
}
.spm-aff-pc__label {
	margin: 0;
	font-weight: 700;
	line-height: 1.3;
}
.spm-aff-pc__sub {
	margin-top: 4px;
	font-size: 14px;
	line-height: 1.4;
}

/* Cloak: hide until JS hydrates so non-affiliates configured to see
   nothing don't get a flash of the placeholder amount. Same pattern as
   .spm-aff-vis-cloak. The failsafe-reveal animation keeps things visible
   if JS never runs (no flash of nothing forever). */
.spm-aff-pc-cloak {
	visibility: hidden !important;
}
@media (prefers-reduced-motion: no-preference) {
	:where(.spm-aff-pc-cloak) {
		animation: spm-aff-vis-failsafe-reveal 0s linear 3s forwards;
	}
}

/* ── Affiliate Stat (atomic single-stat widget) ─────────────────────
   Minimal defaults so Elementor's style controls drive the appearance
   rather than fighting plugin CSS. The layout-direction modifiers handle
   icon-position via flexbox; text alignment is controlled by the Wrapper
   Alignment control on the widget. */
.spm-aff-stat-widget {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 12px;
}
/* Icon position modifiers. */
.spm-aff-stat-widget--icon-top    { flex-direction: column; }
.spm-aff-stat-widget--icon-left   { flex-direction: row; }
.spm-aff-stat-widget--icon-right  { flex-direction: row-reverse; }
.spm-aff-stat-widget--icon-none   { flex-direction: column; gap: 0; }

/* Body holds value + label so they stay grouped regardless of icon placement. */
.spm-aff-stat-widget__body {
	display: flex;
	flex-direction: column;
}
.spm-aff-stat-widget__icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	line-height: 1;
}
.spm-aff-stat-widget__icon i,
.spm-aff-stat-widget__icon svg {
	display: inline-block;
}
.spm-aff-stat-widget__value {
	font-size: 32px;
	font-weight: 700;
	line-height: 1.1;
}
.spm-aff-stat-widget__label {
	font-size: 13px;
	opacity: 0.75;
	letter-spacing: 0.02em;
	text-transform: uppercase;
	margin-top: 4px;
}
/* Alignment within the body: when wrapper is left/right aligned, the body's
   internal text follows along. */
.spm-aff-stat-widget[style*="text-align: left"]   .spm-aff-stat-widget__body { align-items: flex-start; }
.spm-aff-stat-widget[style*="text-align: center"] .spm-aff-stat-widget__body { align-items: center; }
.spm-aff-stat-widget[style*="text-align: right"]  .spm-aff-stat-widget__body { align-items: flex-end; }

/* ── Unclaimed-payout action card (affiliate-facing) ───────────────── */
.spm-aff-unclaimed-card {
	display: flex;
	gap: 14px;
	margin-top: 14px;
	margin-bottom: 14px;
	padding: 16px 18px;
	background: linear-gradient(180deg, #fff7ed 0%, #ffedd5 100%);
	border: 1px solid #fb923c;
	border-left-width: 4px;
	border-radius: 8px;
}
.spm-aff-unclaimed-card__icon {
	font-size: 28px;
	line-height: 1;
	color: #c2410c;
	flex-shrink: 0;
}
.spm-aff-unclaimed-card__body { flex: 1; }
.spm-aff-unclaimed-card__title {
	margin: 0 0 6px 0;
	font-size: 16px;
	font-weight: 700;
	color: #7c2d12;
}
.spm-aff-unclaimed-card__intro {
	margin: 0 0 10px 0;
	color: #7c2d12;
	line-height: 1.5;
}
.spm-aff-unclaimed-card__steps {
	margin: 8px 0 10px 18px;
	padding: 0;
	color: #7c2d12;
	font-size: 14px;
	line-height: 1.6;
}
.spm-aff-unclaimed-card__steps code {
	background: #fff7ed;
	padding: 1px 6px;
	border-radius: 3px;
	font-size: 12px;
	color: #9a3412;
}
.spm-aff-unclaimed-card__steps a { color: #9a3412; font-weight: 600; }
.spm-aff-unclaimed-card__countdown {
	margin: 6px 0 0 0;
	padding: 6px 10px;
	background: rgba(255, 255, 255, 0.55);
	border-radius: 4px;
	font-size: 13px;
	color: #7c2d12;
	font-weight: 600;
}
.spm-aff-unclaimed-card__countdown--urgent {
	background: #fee2e2;
	color: #991b1b;
}

.spm-aff-loading { color: var(--spm-color-muted); font-style: italic; }

/* ── Recent referrals ──────────────────────────────────────────────── */
.spm-aff-recent table { width: 100%; border-collapse: collapse; }
.spm-aff-recent th,
.spm-aff-recent td {
	padding: 8px 12px;
	border-bottom: 1px solid var(--spm-color-border);
	text-align: left;
	font-size: 13px;
}

/* ── Note variants ─────────────────────────────────────────────────── */
.spm-aff-note--warn { color: #b45309; }
.spm-aff-note--info { color: #1d4ed8; }
.spm-aff-note--small { font-size: 12px; }

/* ── Inline payout setup form (PayoutHistory widget) ──────────────── */
.spm-aff-payout-setup {
	margin: 8px 0 0;
	padding: 12px 0 0;
	border-top: 1px solid var(--spm-color-border);
}
.spm-aff-payout-setup__intro {
	margin: 0 0 10px;
	font-weight: 600;
}

/* ── Account form (DashboardWidget — payout settings section) ─────── */
.spm-aff-card form .spm-aff-field {
	margin-bottom: 12px;
}
.spm-aff-card form .spm-aff-field input[disabled] {
	background: var(--spm-color-bg-soft);
	cursor: not-allowed;
}

/* ── Slug editor ──────────────────────────────────────────────────── */
.spm-aff-slug-input {
	display: flex;
	align-items: stretch;
	border: 1px solid var(--spm-color-border);
	border-radius: var(--spm-radius);
	overflow: hidden;
}
.spm-aff-slug-input__prefix {
	display: flex;
	align-items: center;
	padding: 0 10px;
	background: var(--spm-color-bg-soft);
	font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
	font-size: 13px;
	color: var(--spm-color-muted);
	border-right: 1px solid var(--spm-color-border);
}
.spm-aff-slug-input input {
	flex: 1 1 auto;
	border: 0;
	padding: 9px 10px;
	font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
	font-size: 14px;
	background: transparent;
}
.spm-aff-slug-input input:focus {
	outline: none;
	background: #fff;
}
[data-spm-aff-slug-status] {
	display: block;
	margin-top: 6px;
	font-size: 12px;
	min-height: 16px;
}
[data-spm-aff-slug-status].is-available { color: #166534; }
[data-spm-aff-slug-status].is-unavailable { color: #b91c1c; }
[data-spm-aff-slug-status].is-checking { color: var(--spm-color-muted); }

/* ── Deep link builder ────────────────────────────────────────────── */
.spm-aff-deeplink-result {
	margin-top: 12px;
	padding-top: 12px;
	border-top: 1px solid var(--spm-color-border);
}

/* ── Onboarding checklist widget ──────────────────────────────────── */
.spm-aff-onboarding {
	padding: 16px 18px;
	background: linear-gradient(135deg, #eef2ff 0%, #f8fafc 100%);
	border: 1px solid #c7d2fe;
	border-radius: var(--spm-radius);
	margin-bottom: 16px;
}
.spm-aff-onboarding__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin-bottom: 12px;
}
.spm-aff-onboarding__header h4 {
	margin: 0;
	font-size: 16px;
	color: #312e81;
}
.spm-aff-onboarding__progress {
	font-size: 13px;
	font-weight: 600;
	color: #4338ca;
	background: #fff;
	padding: 2px 10px;
	border-radius: 999px;
}
.spm-aff-checklist {
	list-style: none;
	margin: 0;
	padding: 0;
}
.spm-aff-checklist__item {
	display: flex;
	gap: 10px;
	padding: 10px 0;
	border-top: 1px solid rgba(199, 210, 254, 0.6);
}
.spm-aff-checklist__item:first-child { border-top: 0; }
.spm-aff-checklist__icon {
	flex: 0 0 24px;
	width: 24px;
	height: 24px;
	line-height: 24px;
	text-align: center;
	font-weight: 700;
	border-radius: 50%;
}
.spm-aff-checklist__item.is-done .spm-aff-checklist__icon {
	background: #16a34a;
	color: #fff;
}
.spm-aff-checklist__item.is-todo .spm-aff-checklist__icon {
	background: #fff;
	color: var(--spm-color-muted);
	border: 1px solid #c7d2fe;
}
.spm-aff-checklist__label {
	font-weight: 600;
	color: #1e293b;
}
.spm-aff-checklist__item.is-done .spm-aff-checklist__label {
	color: var(--spm-color-muted);
	text-decoration: line-through;
	text-decoration-thickness: 1px;
}
.spm-aff-checklist__help {
	margin-top: 2px;
	font-size: 13px;
	color: #475569;
}
.spm-aff-checklist__help code {
	background: #fff;
	padding: 1px 6px;
	border-radius: 3px;
	font-size: 12px;
}
