/**
 * RecLite Headless — Finance (Billing tab + anonymous pay-link)
 *
 * Loads after reclite-headless.css, so the shared tokens (--reclite-color-*,
 * .rl-card, .rl-btn family, .rl-modal-info, .rl-pill) are already available.
 * Only finance-specific additions live here.
 *
 * Buttons: this file adds no new button styles — it reuses the shared
 * .rl-btn / .rl-btn-soft / .rl-btn-quiet / .rl-btn-danger(-soft) tiers, which
 * already carry the :not(#_) theme-beating specificity.
 *
 * WCAG 2.1 AA: money uses tabular numerals; status pills carry text + colour
 * with a forced-colors fallback; focusable controls inherit the shared focus
 * ring.
 */

/* -------- Panel rhythm -------- */
/* Even spacing between the stacked section cards + a touch more breathing room
   inside each, so the Billing tab reads as a tidy set of grouped cards. */
[data-rl="billing"] > .rl-card {
	margin-bottom: 1.25rem;
	padding: 1.25rem 1.35rem;
}
[data-rl="billing"] > .rl-card:last-of-type {
	margin-bottom: 0;
}
[data-rl="billing"] .rl-card > h3:first-child {
	margin-top: 0;
}

/* Tabular numerals so money/columns align regardless of digit widths. */
.rl-num,
.rl-fin-amount,
.rl-fin-table .rl-num {
	font-variant-numeric: tabular-nums;
	font-feature-settings: "tnum" 1;
	text-align: right;
	white-space: nowrap;
}

.rl-fin-amount {
	font-weight: 600;
}

/* -------- Balance hero -------- */
.rl-fin-hero {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 1.25rem 2rem;
	margin: 0.35rem 0 0;
	padding: 1.4rem 1.5rem;
	border-radius: 14px;
	color: #fff;
	background:
		linear-gradient(135deg,
			var(--reclite-color-primary, #243b80) 0%,
			color-mix(in srgb, var(--reclite-color-primary, #243b80) 78%, #000) 100%);
	box-shadow: 0 8px 22px -14px rgba(0, 0, 0, 0.55);
}
.rl-fin-hero.is-clear {
	background:
		linear-gradient(135deg, #1e7d34 0%, #14622a 100%);
}
.rl-fin-hero-main {
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
	min-width: 0;
}
.rl-fin-hero-label {
	font-size: 0.78rem;
	text-transform: uppercase;
	letter-spacing: 0.08em;
	opacity: 0.85;
}
.rl-fin-hero-amount {
	font-size: 2.6rem;
	font-weight: 700;
	line-height: 1;
	text-align: left;
}
.rl-fin-hero-clear {
	display: inline-flex;
	align-items: center;
	gap: 0.4rem;
	font-size: 0.95rem;
	font-weight: 600;
	opacity: 0.95;
}
/* The hero Pay button overrides the shared pill so it reads on the dark hero:
   a solid white button with primary-coloured text. Beats the parent theme's
   green pill with the same :not(#_) id-specificity idiom used across the plugin. */
.rl-fin-hero-pay:not(#_) {
	align-self: flex-start;
	margin-top: 0.35rem;
	background: #fff;
	color: var(--reclite-color-primary, #243b80);
	border: none;
	font-weight: 700;
}
.rl-fin-hero-pay:not(#_):hover,
.rl-fin-hero-pay:not(#_):focus-visible {
	background: #eef2fb;
	color: var(--reclite-color-primary, #243b80);
}
.rl-fin-hero-side {
	display: flex;
	flex-wrap: wrap;
	gap: 0.65rem;
}
.rl-fin-chip {
	display: flex;
	flex-direction: column;
	gap: 0.2rem;
	padding: 0.6rem 0.9rem;
	border-radius: 10px;
	background: rgba(255, 255, 255, 0.14);
	backdrop-filter: blur(2px);
	min-width: 8.5rem;
}
.rl-fin-chip-label {
	font-size: 0.72rem;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	opacity: 0.85;
}
.rl-fin-chip-value {
	font-size: 1.05rem;
	font-weight: 600;
}
/* Pills sit inside the translucent chip on the dark hero — force readable ink. */
.rl-fin-chip-value .rl-fin-pill {
	background: #fff;
	color: var(--reclite-color-primary, #243b80);
	border-color: transparent;
}
.rl-fin-hint {
	margin: 0.6rem 0 0;
	font-size: 0.9rem;
}
/* Let the summary card carry the hero edge-to-edge (no inner heading gap crowd). */
.rl-fin-summary #rl-fin-summary-h,
.rl-fin-summary h3 {
	margin-bottom: 0.25rem;
}

/* -------- Card heads with a trailing action/field -------- */
.rl-fin-card-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	flex-wrap: wrap;
}
.rl-fin-card-head h3 {
	margin: 0;
}
.rl-fin-year {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	margin: 0;
}
.rl-fin-year label {
	font-size: 0.9rem;
	margin: 0;
}
.rl-fin-year select {
	min-width: 6rem;
}

.rl-fin-subhead {
	margin: 1.4rem 0 0.6rem;
	font-size: 0.95rem;
	font-weight: 700;
	letter-spacing: 0.01em;
	color: var(--reclite-color-heading, #1d2531);
}
.rl-fin-subhead:first-child {
	margin-top: 0.25rem;
}

/* -------- Tables -------- */
.rl-fin-table-wrap {
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
	border: 1px solid var(--reclite-color-border, #e3e7ee);
	border-radius: 10px;
}
.rl-fin-table {
	width: 100%;
	border-collapse: collapse;
	font-size: 0.94rem;
}
.rl-fin-table caption {
	text-align: left;
}
.rl-fin-table th,
.rl-fin-table td {
	padding: 0.7rem 0.85rem;
	border-bottom: 1px solid var(--reclite-color-border, #edf0f5);
	vertical-align: middle;
	text-align: left;
}
.rl-fin-table thead th {
	background: var(--reclite-color-surface-alt, #f5f7fb);
	border-bottom: 1px solid var(--reclite-color-border, #dde3ee);
}
.rl-fin-table th[scope="col"] {
	font-size: 0.74rem;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	color: var(--reclite-color-muted, #5a6473);
	font-weight: 700;
}
.rl-fin-table tbody tr {
	transition: background-color 0.12s ease;
}
.rl-fin-table tbody tr:hover {
	background: var(--reclite-color-surface-alt, #f7f9fc);
}
.rl-fin-table tbody tr:last-child td {
	border-bottom: none;
}
.rl-fin-table tfoot th,
.rl-fin-table tfoot td {
	font-weight: 700;
	background: var(--reclite-color-surface-alt, #f5f7fb);
	border-top: 2px solid var(--reclite-color-border, #cdd4df);
	border-bottom: none;
	padding: 0.7rem 0.85rem;
}
.rl-fin-row-actions {
	display: flex;
	gap: 0.4rem;
	justify-content: flex-end;
	flex-wrap: wrap;
}

/* A small inline tag (e.g. "Tax-deductible"). */
.rl-fin-tag {
	display: inline-block;
	margin-left: 0.4rem;
	padding: 0.05rem 0.4rem;
	font-size: 0.72rem;
	border-radius: 4px;
	background: color-mix(in srgb, var(--reclite-color-primary, #243b80) 12%, transparent);
	color: var(--reclite-color-primary, #243b80);
	white-space: nowrap;
}

/* -------- Status pills (text + colour) -------- */
.rl-fin-pill {
	display: inline-block;
	padding: 0.1rem 0.55rem;
	border-radius: 999px;
	font-size: 0.78rem;
	font-weight: 600;
	line-height: 1.5;
	border: 1px solid transparent;
}
.rl-fin-pill-good {
	background: #e6f4ea;
	color: #1e7d34;
	border-color: #b7e0c2;
}
.rl-fin-pill-warn {
	background: #fdf3e2;
	color: #9a6412;
	border-color: #f0d8a8;
}
.rl-fin-pill-bad {
	background: #fdeceb;
	color: #b02a20;
	border-color: #f2c2bd;
}
.rl-fin-pill-neutral {
	background: #eef1f6;
	color: #3b4453;
	border-color: #d5dbe6;
}

/* -------- Detail modal content -------- */
.rl-fin-kv {
	display: grid;
	grid-template-columns: minmax(7rem, auto) 1fr;
	gap: 0.35rem 1rem;
	margin: 0 0 1rem;
}
.rl-fin-kv dt {
	font-weight: 600;
	color: var(--reclite-color-muted, #5a6473);
}
.rl-fin-kv dd {
	margin: 0;
}
.rl-fin-fees {
	display: grid;
	grid-template-columns: 1fr auto;
	gap: 0.3rem 1rem;
	margin: 0 0 1rem;
	padding: 0.75rem 0;
	border-top: 1px solid var(--reclite-color-border, #e3e7ee);
	border-bottom: 1px solid var(--reclite-color-border, #e3e7ee);
}
.rl-fin-fees dt { margin: 0; }
.rl-fin-fees dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.rl-fin-fees .is-total {
	font-weight: 700;
	padding-top: 0.3rem;
	border-top: 1px solid var(--reclite-color-border, #e3e7ee);
}
.rl-fin-charge {
	margin: 0 0 0.75rem;
	padding: 0.6rem 0.75rem;
	border: 1px solid var(--reclite-color-border, #e3e7ee);
	border-radius: 8px;
}
.rl-fin-charge-head {
	display: flex;
	justify-content: space-between;
	gap: 1rem;
	font-weight: 600;
}
.rl-fin-lines {
	list-style: none;
	margin: 0.5rem 0 0;
	padding: 0;
}
.rl-fin-lines li {
	display: flex;
	justify-content: space-between;
	gap: 1rem;
	padding: 0.2rem 0;
	font-size: 0.9rem;
	color: var(--reclite-color-muted, #4a5361);
}
.rl-fin-lines li span:last-child { font-variant-numeric: tabular-nums; }
.rl-fin-modal-amount {
	font-size: 1.6rem;
	margin: 0 0 0.75rem;
	text-align: left;
}

/* -------- Saved cards -------- */
.rl-fin-methods-list {
	list-style: none;
	margin: 0.5rem 0 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
}
.rl-fin-method {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	flex-wrap: wrap;
	padding: 0.75rem 0.95rem 0.75rem 2.9rem;
	border: 1px solid var(--reclite-color-border, #d9dee8);
	border-radius: 10px;
	background: var(--reclite-color-surface, #fff);
	position: relative;
}
/* Decorative card glyph so a saved card reads as a card at a glance. */
.rl-fin-method::before {
	content: "";
	position: absolute;
	left: 0.85rem;
	top: 50%;
	transform: translateY(-50%);
	width: 1.5rem;
	height: 1.05rem;
	border-radius: 3px;
	background: color-mix(in srgb, var(--reclite-color-primary, #243b80) 16%, #fff);
	box-shadow: inset 0 3px 0 color-mix(in srgb, var(--reclite-color-primary, #243b80) 45%, #fff);
}
.rl-fin-method-label {
	font-weight: 600;
	font-variant-numeric: tabular-nums;
}
.rl-fin-method-actions {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	flex-wrap: wrap;
}
.rl-fin-confirm {
	font-size: 0.9rem;
	color: var(--reclite-color-muted, #4a5361);
}

/* -------- Autopay method control -------- */
.rl-fin-autopay {
	margin-top: 1rem;
	padding-top: 0.85rem;
	border-top: 1px solid var(--reclite-color-border, #e3e7ee);
}
.rl-fin-autopay > label {
	display: block;
	font-weight: 600;
	margin-bottom: 0.35rem;
}
.rl-fin-autopay-row {
	display: flex;
	gap: 0.6rem;
	align-items: center;
	flex-wrap: wrap;
}
.rl-fin-autopay-row select {
	min-width: 14rem;
	flex: 1 1 14rem;
}

/* -------- Stub note (card capture unavailable) -------- */
.rl-fin-stub-note {
	margin: 0.75rem 0 0;
	padding: 0.7rem 0.85rem;
	border-radius: 8px;
	background: #fdf3e2;
	color: #7a5410;
	border: 1px solid #f0d8a8;
	font-size: 0.92rem;
}

/* -------- Pay a balance: dev simulator panel -------- */
.rl-fin-devnote {
	margin: 0 0 1rem;
	padding: 0.7rem 0.85rem;
	border-radius: 8px;
	background: #eef1f6;
	color: #3b4453;
	border: 1px solid #d5dbe6;
	font-size: 0.9rem;
}
.rl-fin-sim {
	display: flex;
	flex-direction: column;
	gap: 0.9rem;
	margin-top: 0.25rem;
}
.rl-fin-sim-primary:not(#_) {
	align-self: flex-start;
}
.rl-fin-sim-alt {
	display: flex;
	align-items: center;
	gap: 0.5rem 0.65rem;
	flex-wrap: wrap;
	padding-top: 0.75rem;
	border-top: 1px dashed var(--reclite-color-border, #e3e7ee);
}
.rl-fin-sim-alt-label {
	font-size: 0.85rem;
	color: var(--reclite-color-muted, #5a6473);
	margin-right: 0.15rem;
}

/* Outcome panel (success / failure) — shared by the pay flow and pay-link. */
.rl-fin-result {
	text-align: center;
	padding: 0.75rem 0.5rem 0.25rem;
}
.rl-fin-result-icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 3.5rem;
	height: 3.5rem;
	border-radius: 999px;
	margin-bottom: 0.85rem;
}
.rl-fin-result-good .rl-fin-result-icon {
	background: #e6f4ea;
	color: #1e7d34;
}
.rl-fin-result-bad .rl-fin-result-icon {
	background: #fdeceb;
	color: #b02a20;
}
.rl-fin-result-title {
	margin: 0 0 0.4rem;
	font-size: 1.3rem;
}
.rl-fin-result-msg {
	margin: 0 auto 1.25rem;
	max-width: 34ch;
	color: var(--reclite-color-muted, #5a6473);
}
.rl-fin-result-actions {
	justify-content: center;
}

/* -------- Pay-link page -------- */
.rl-fin-paylink-summary {
	display: grid;
	grid-template-columns: auto 1fr;
	gap: 0.4rem 1.25rem;
	margin: 0 0 1rem;
}
.rl-fin-paylink-summary dt {
	font-weight: 600;
	color: var(--reclite-color-muted, #5a6473);
}
.rl-fin-paylink-summary dd {
	margin: 0;
}
.rl-fin-paylink-summary .rl-fin-amount {
	font-size: 1.4rem;
	text-align: left;
}

/* -------- Responsive -------- */
@media (max-width: 640px) {
	.rl-fin-kv {
		grid-template-columns: 1fr;
		gap: 0.15rem;
	}
	.rl-fin-kv dt { margin-top: 0.5rem; }
	.rl-fin-autopay-row select { min-width: 0; }

	.rl-fin-hero {
		flex-direction: column;
		align-items: stretch;
		padding: 1.2rem 1.2rem;
	}
	.rl-fin-hero-amount { font-size: 2.15rem; }
	.rl-fin-hero-pay:not(#_) { align-self: stretch; text-align: center; }
	.rl-fin-hero-side { width: 100%; }
	.rl-fin-chip { flex: 1 1 8rem; }

	/* Billing tables → stacked cards instead of a horizontal scroll. Each cell
	   shows its column name (from data-lbl); the first cell is the card heading
	   and the action cell keeps its buttons with no label. */
	.rl-fin-table-wrap { overflow-x: visible; }
	.rl-fin-table { min-width: 0; }
	.rl-fin-table,
	.rl-fin-table tbody { display: block; width: 100%; }
	.rl-fin-table thead { display: none; }
	.rl-fin-table tbody tr {
		display: block;
		padding: 8px 12px;
		border-bottom: 1px solid var(--reclite-color-border, #edf0f5);
	}
	.rl-fin-table tbody tr:last-child { border-bottom: 0; }
	.rl-fin-table tbody td {
		display: flex;
		justify-content: space-between;
		align-items: baseline;
		gap: 14px;
		padding: 5px 0;
		border: 0;
		text-align: right;
	}
	.rl-fin-table tbody td::before {
		content: attr(data-lbl);
		flex: 0 0 auto;
		font-size: 0.74rem;
		text-transform: uppercase;
		letter-spacing: 0.03em;
		font-weight: 700;
		color: var(--reclite-color-muted, #5a6473);
		text-align: left;
	}
	.rl-fin-table tbody td.rl-td-primary {
		justify-content: flex-start;
		text-align: left;
		font-weight: 700;
		font-size: 0.98rem;
		padding-bottom: 6px;
	}
	.rl-fin-table tbody td.rl-td-primary::before { content: none; }
	.rl-fin-table tbody td.rl-fin-row-actions {
		justify-content: flex-end;
		padding-top: 8px;
	}
	.rl-fin-table tbody td.rl-fin-row-actions::before { content: none; }
	/* Tax table footer total → its own block row. */
	.rl-fin-table tfoot,
	.rl-fin-table tfoot tr { display: block; }
	.rl-fin-table tfoot th,
	.rl-fin-table tfoot td {
		display: flex;
		justify-content: space-between;
		gap: 14px;
	}
}

/* -------- Forced-colors (Windows High Contrast) -------- */
@media (forced-colors: active) {
	.rl-fin-pill {
		border: 1px solid ButtonText;
		background: ButtonFace;
		color: ButtonText;
		forced-color-adjust: none;
	}
	.rl-fin-stat,
	.rl-fin-method,
	.rl-fin-charge,
	.rl-fin-stub-note,
	.rl-fin-tag {
		border: 1px solid ButtonText;
	}
	.rl-fin-stub-note,
	.rl-fin-devnote {
		background: Canvas;
		color: CanvasText;
		border: 1px solid ButtonText;
	}
}
