/* Wallet Budget Companion — dashboard styles. No framework; light/dark via prefers-color-scheme. */

:root {
	color-scheme: light dark;
	--font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
	--mono: ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;

	--bg: #f6f7f9;
	--surface: #ffffff;
	--surface-2: #f1f3f6;
	--surface-3: #e7eaef;
	--text: #1a1d23;
	--muted: #626a76;
	--border: #dfe3e8;
	--border-strong: #c7cdd5;
	--accent: #0f766e;
	--accent-hover: #0c5f58;
	--accent-soft: #e0f2ef;
	--accent-text: #ffffff;
	--ok: #15803d;
	--ok-soft: #e3f5e8;
	--bad: #c2261d;
	--bad-soft: #fde8e6;
	--warn: #a15c07;
	--warn-soft: #fdf1dc;
	--info: #1d5fbf;
	--info-soft: #e5eefc;
	--focus: #2563eb;
	--wa-bg: #efe7dc;
	--wa-bubble: #d9fdd3;
	--wa-text: #111b21;

	--radius: 12px;
	--radius-sm: 8px;
	--shadow: 0 1px 2px rgb(16 24 40 / 0.05), 0 1px 3px rgb(16 24 40 / 0.06);
	--shadow-lg: 0 10px 30px rgb(16 24 40 / 0.12);
	--space-1: 4px;
	--space-2: 8px;
	--space-3: 12px;
	--space-4: 16px;
	--space-5: 24px;
	--space-6: 32px;
	--content: 1200px;
}

@media (prefers-color-scheme: dark) {
	:root {
		--bg: #111418;
		--surface: #1a1e24;
		--surface-2: #21262d;
		--surface-3: #2b313a;
		--text: #e7eaee;
		--muted: #9aa3ae;
		--border: #2d333b;
		--border-strong: #3d444e;
		--accent: #2dd4bf;
		--accent-hover: #5eead4;
		--accent-soft: #123c38;
		--accent-text: #06201d;
		--ok: #4ade80;
		--ok-soft: #14301f;
		--bad: #f87171;
		--bad-soft: #3a1717;
		--warn: #fbbf24;
		--warn-soft: #362a0f;
		--info: #7aa7f5;
		--info-soft: #17263f;
		--focus: #7aa7f5;
		--wa-bg: #0b141a;
		--wa-bubble: #005c4b;
		--wa-text: #e9edef;
		--shadow: 0 1px 2px rgb(0 0 0 / 0.4);
		--shadow-lg: 0 10px 30px rgb(0 0 0 / 0.5);
	}
}

/* ---------------------------------------------------------------- base */

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

html {
	-webkit-text-size-adjust: 100%;
	text-size-adjust: 100%;
}

body {
	margin: 0;
	background: var(--bg);
	color: var(--text);
	font: 15px/1.5 var(--font);
	font-variant-numeric: tabular-nums;
	-webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
	line-height: 1.25;
	margin: 0;
}

h1 {
	font-size: 1.6rem;
	font-weight: 700;
	letter-spacing: -0.01em;
}

p {
	margin: 0 0 var(--space-3);
}

a {
	color: var(--accent);
	text-underline-offset: 2px;
}

a:hover {
	color: var(--accent-hover);
}

code,
.mono {
	font-family: var(--mono);
	font-size: 0.88em;
}

code {
	background: var(--surface-2);
	border: 1px solid var(--border);
	border-radius: 5px;
	padding: 0.05em 0.35em;
}

:focus-visible {
	outline: 2px solid var(--focus);
	outline-offset: 2px;
	border-radius: 4px;
}

#main:focus {
	outline: none;
}

.visually-hidden {
	position: absolute !important;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
}

.skip-link {
	position: absolute;
	left: var(--space-3);
	top: -48px;
	z-index: 100;
	background: var(--surface);
	padding: var(--space-2) var(--space-3);
	border-radius: var(--radius-sm);
	box-shadow: var(--shadow-lg);
}

.skip-link:focus {
	top: var(--space-3);
}

[hidden] {
	display: none !important;
}

.muted {
	color: var(--muted);
}

.small {
	font-size: 0.85rem;
}

.nowrap {
	white-space: nowrap;
}

.neg,
.error-text {
	color: var(--bad);
}

.pos {
	color: var(--ok);
}

.warn-text {
	color: var(--warn);
}

.upper {
	text-transform: uppercase;
}

/* ---------------------------------------------------------------- top bar */

.topbar {
	position: sticky;
	top: 0;
	z-index: 20;
	background: color-mix(in srgb, var(--surface) 88%, transparent);
	backdrop-filter: saturate(1.4) blur(10px);
	-webkit-backdrop-filter: saturate(1.4) blur(10px);
	border-bottom: 1px solid var(--border);
}

.topbar-inner {
	max-width: var(--content);
	margin: 0 auto;
	padding: 0 var(--space-4);
	display: flex;
	align-items: center;
	gap: var(--space-4);
	min-height: 56px;
}

.brand {
	display: flex;
	align-items: center;
	gap: var(--space-2);
	color: var(--text);
	text-decoration: none;
	font-weight: 700;
	white-space: nowrap;
}

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

.brand-mark {
	display: inline-grid;
	place-items: center;
	width: 28px;
	height: 28px;
	border-radius: 8px;
	background: var(--accent);
	color: var(--accent-text);
	font-weight: 800;
	font-size: 0.95rem;
}

.brand-mark-lg {
	width: 44px;
	height: 44px;
	border-radius: 12px;
	font-size: 1.3rem;
	margin-bottom: var(--space-3);
}

.nav {
	display: flex;
	gap: 2px;
	flex: 1;
	min-width: 0;
}

.nav a {
	padding: 6px 12px;
	border-radius: 999px;
	color: var(--muted);
	text-decoration: none;
	font-weight: 500;
	white-space: nowrap;
}

.nav a:hover {
	color: var(--text);
	background: var(--surface-2);
}

.nav a[aria-current='page'] {
	color: var(--accent);
	background: var(--accent-soft);
	font-weight: 600;
}

.topbar-end {
	display: flex;
	align-items: center;
	gap: var(--space-2);
}

.period-pill {
	font-size: 0.82rem;
	color: var(--muted);
	background: var(--surface-2);
	border: 1px solid var(--border);
	border-radius: 999px;
	padding: 3px 10px;
	white-space: nowrap;
}

.setup-banner {
	background: var(--warn-soft);
	color: var(--text);
	text-align: center;
	font-size: 0.9rem;
	padding: 6px var(--space-4);
	border-top: 1px solid var(--border);
}

main {
	max-width: var(--content);
	margin: 0 auto;
	padding: var(--space-5) var(--space-4) 64px;
}

body.bare main {
	max-width: none;
	padding: 0;
}

/* ---------------------------------------------------------------- buttons & inputs */

.btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: var(--space-2);
	min-height: 36px;
	padding: 0 14px;
	border: 1px solid var(--border-strong);
	border-radius: var(--radius-sm);
	background: var(--surface);
	color: var(--text);
	font: inherit;
	font-weight: 550;
	cursor: pointer;
	white-space: nowrap;
	transition:
		background-color 0.15s,
		border-color 0.15s;
}

.btn:hover:not(:disabled) {
	background: var(--surface-2);
}

.btn:disabled {
	opacity: 0.55;
	cursor: not-allowed;
}

.btn-primary {
	background: var(--accent);
	border-color: var(--accent);
	color: var(--accent-text);
}

.btn-primary:hover:not(:disabled) {
	background: var(--accent-hover);
	border-color: var(--accent-hover);
}

.btn-ghost {
	background: transparent;
	border-color: transparent;
	color: var(--muted);
}

.btn-ghost:hover:not(:disabled) {
	color: var(--text);
}

.btn-sm {
	min-height: 30px;
	padding: 0 10px;
	font-size: 0.875rem;
}

.btn-icon {
	width: 36px;
	padding: 0;
	font-size: 1.3rem;
	line-height: 1;
}

.btn-block {
	width: 100%;
}

.btn.busy::before {
	content: '';
	width: 14px;
	height: 14px;
	border: 2px solid currentColor;
	border-right-color: transparent;
	border-radius: 50%;
	animation: spin 0.7s linear infinite;
}

.button-row {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--space-2);
}

input,
select,
textarea {
	font: inherit;
	color: var(--text);
	background: var(--surface);
	border: 1px solid var(--border-strong);
	border-radius: var(--radius-sm);
	min-height: 36px;
	padding: 6px 10px;
	max-width: 100%;
}

input[type='checkbox'] {
	min-height: 0;
	width: 18px;
	height: 18px;
	accent-color: var(--accent);
	cursor: pointer;
	vertical-align: middle;
	margin: 0;
}

input[type='file'] {
	border-style: dashed;
	padding: 8px;
	width: 100%;
}

input:focus-visible,
select:focus-visible {
	outline: 2px solid var(--focus);
	outline-offset: 0;
	border-color: var(--focus);
}

/* Toggle switch look for flag checkboxes (still a real checkbox). */
input.switch {
	appearance: none;
	-webkit-appearance: none;
	position: relative;
	width: 38px;
	height: 22px;
	flex: none;
	border-radius: 999px;
	background: var(--surface-3);
	border: 1px solid var(--border-strong);
	transition: background-color 0.15s;
}

input.switch::after {
	content: '';
	position: absolute;
	top: 2px;
	left: 2px;
	width: 16px;
	height: 16px;
	border-radius: 50%;
	background: #fff;
	box-shadow: 0 1px 2px rgb(0 0 0 / 0.3);
	transition: transform 0.15s;
}

input.switch:checked {
	background: var(--accent);
	border-color: var(--accent);
}

input.switch:checked::after {
	transform: translateX(16px);
}

.field {
	display: flex;
	flex-direction: column;
	gap: 5px;
	margin-bottom: var(--space-4);
	min-width: 0;
}

.field > label {
	font-weight: 600;
	font-size: 0.9rem;
}

.field-flag > label,
.inline-flag {
	display: flex;
	align-items: center;
	gap: var(--space-3);
	font-weight: 500;
	cursor: pointer;
}

.help {
	color: var(--muted);
	font-size: 0.82rem;
}

.field-error {
	color: var(--bad);
	font-size: 0.85rem;
}

.field-error:empty {
	display: none;
}

.has-error input,
.has-error select {
	border-color: var(--bad);
}

.form-grid {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
	column-gap: var(--space-4);
}

.inline-fields {
	display: flex;
	flex-wrap: wrap;
	align-items: flex-end;
	gap: 0 var(--space-5);
}

/* ---------------------------------------------------------------- layout blocks */

.page-header {
	display: flex;
	flex-wrap: wrap;
	align-items: flex-end;
	justify-content: space-between;
	gap: var(--space-3) var(--space-5);
	margin-bottom: var(--space-5);
}

.page-header p {
	margin: 4px 0 0;
}

.page-actions {
	display: flex;
	flex-wrap: wrap;
	gap: var(--space-2);
}

.card {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
	padding: var(--space-5);
	margin-bottom: var(--space-4);
	min-width: 0;
}

.card-title {
	font-size: 1.05rem;
	font-weight: 650;
	margin-bottom: var(--space-3);
}

.card-head {
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	justify-content: space-between;
	gap: var(--space-2);
	margin-bottom: var(--space-3);
}

.card-head .card-title {
	margin: 0;
}

.stack > .card:last-child {
	margin-bottom: 0;
}

.callout {
	border: 1px solid;
	border-radius: var(--radius-sm);
	padding: var(--space-3) var(--space-4);
	margin: 0 0 var(--space-4);
	font-size: 0.92rem;
}

.action-result .callout {
	margin: var(--space-3) 0 0;
}

.callout-info {
	background: var(--info-soft);
	border-color: color-mix(in srgb, var(--info) 30%, transparent);
}

.callout-ok {
	background: var(--ok-soft);
	border-color: color-mix(in srgb, var(--ok) 30%, transparent);
}

.callout-warn {
	background: var(--warn-soft);
	border-color: color-mix(in srgb, var(--warn) 35%, transparent);
}

.callout-error {
	background: var(--bad-soft);
	border-color: color-mix(in srgb, var(--bad) 35%, transparent);
}

.callout-actions {
	margin-top: var(--space-2);
}

.callout .kv {
	margin-top: var(--space-2);
}

.badge {
	display: inline-block;
	padding: 1px 8px;
	border-radius: 999px;
	font-size: 0.75rem;
	font-weight: 600;
	line-height: 1.6;
	white-space: nowrap;
	vertical-align: middle;
}

.badge-ok {
	background: var(--ok-soft);
	color: var(--ok);
}

.badge-bad {
	background: var(--bad-soft);
	color: var(--bad);
}

.badge-warn {
	background: var(--warn-soft);
	color: var(--warn);
}

.badge-info {
	background: var(--info-soft);
	color: var(--info);
}

.badge-neutral {
	background: var(--surface-2);
	color: var(--muted);
}

.kv {
	display: grid;
	grid-template-columns: max-content 1fr;
	gap: 2px var(--space-4);
	margin: var(--space-3) 0 0;
	font-size: 0.9rem;
}

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

.kv dd {
	margin: 0;
	font-weight: 600;
}

.empty {
	text-align: center;
	padding: var(--space-6) var(--space-4);
	color: var(--muted);
	background: var(--surface);
	border: 1px dashed var(--border-strong);
	border-radius: var(--radius);
}

.empty p:last-child {
	margin-bottom: 0;
}

.loading {
	display: flex;
	align-items: center;
	gap: var(--space-2);
	color: var(--muted);
	padding: var(--space-5) 0;
}

.loading-page {
	justify-content: center;
	min-height: 50vh;
}

.spinner {
	width: 18px;
	height: 18px;
	border: 2px solid var(--border-strong);
	border-top-color: var(--accent);
	border-radius: 50%;
	animation: spin 0.7s linear infinite;
}

@keyframes spin {
	to {
		transform: rotate(360deg);
	}
}

.is-loading {
	opacity: 0.55;
	transition: opacity 0.2s;
	pointer-events: none;
}

.chips,
.toc {
	display: flex;
	flex-wrap: wrap;
	gap: var(--space-2);
}

.toc {
	margin-bottom: var(--space-4);
}

.chip {
	display: inline-flex;
	align-items: center;
	min-height: 30px;
	padding: 0 12px;
	border-radius: 999px;
	border: 1px solid var(--border-strong);
	background: var(--surface);
	color: var(--text);
	font: inherit;
	font-size: 0.875rem;
	text-decoration: none;
	cursor: pointer;
}

.chip:hover {
	background: var(--surface-2);
	color: var(--text);
}

.chip[aria-pressed='true'] {
	background: var(--accent-soft);
	border-color: var(--accent);
	color: var(--accent);
	font-weight: 600;
}

/* ---------------------------------------------------------------- toasts & flash */

.toasts {
	position: fixed;
	right: var(--space-4);
	bottom: var(--space-4);
	z-index: 50;
	display: flex;
	flex-direction: column;
	gap: var(--space-2);
	max-width: min(420px, calc(100vw - 32px));
}

.toast {
	background: var(--surface);
	border: 1px solid var(--border);
	border-left: 4px solid var(--info);
	border-radius: var(--radius-sm);
	box-shadow: var(--shadow-lg);
	padding: 10px 14px;
	font-size: 0.9rem;
	animation: toast-in 0.2s ease-out;
}

.toast-ok {
	border-left-color: var(--ok);
}

.toast-warn {
	border-left-color: var(--warn);
}

.toast-error {
	border-left-color: var(--bad);
}

.toast-out {
	opacity: 0;
	transform: translateY(6px);
	transition:
		opacity 0.3s,
		transform 0.3s;
}

@keyframes toast-in {
	from {
		opacity: 0;
		transform: translateY(8px);
	}
}

.flash-saved {
	animation: flash-saved 1.6s ease-out;
}

.flash-error {
	animation: flash-error 1.6s ease-out;
}

@keyframes flash-saved {
	0%,
	40% {
		box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 45%, transparent);
		border-color: var(--ok);
	}
}

@keyframes flash-error {
	0%,
	40% {
		box-shadow: 0 0 0 3px color-mix(in srgb, var(--bad) 45%, transparent);
		border-color: var(--bad);
	}
}

[aria-busy='true'] {
	opacity: 0.6;
}

/* ---------------------------------------------------------------- meter */

.meter {
	position: relative;
	height: 6px;
	border-radius: 999px;
	background: var(--surface-3);
	overflow: visible;
}

.meter-fill {
	display: block;
	height: 100%;
	border-radius: inherit;
	background: var(--accent);
}

.meter-near .meter-fill {
	background: var(--warn);
}

.meter-over .meter-fill {
	background: var(--bad);
}

.meter-marker {
	position: absolute;
	top: -3px;
	width: 2px;
	height: 12px;
	margin-left: -1px;
	background: var(--text);
	border-radius: 1px;
	opacity: 0.7;
}

.meter-legend {
	display: flex;
	justify-content: space-between;
	gap: var(--space-3);
	margin-top: var(--space-2);
}

/* ---------------------------------------------------------------- screens (login / secrets) */

.screen {
	min-height: 100vh;
	display: grid;
	place-items: center;
	padding: var(--space-5) var(--space-4);
}

.screen-card {
	width: 100%;
	max-width: 380px;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 16px;
	box-shadow: var(--shadow-lg);
	padding: var(--space-6);
}

.screen-card-wide {
	max-width: 560px;
}

.screen-card h1 {
	font-size: 1.4rem;
	margin-bottom: var(--space-2);
}

.screen-card .field {
	margin-top: var(--space-4);
}

.code {
	background: var(--surface-2);
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	padding: var(--space-3) var(--space-4);
	overflow-x: auto;
	margin: 0 0 var(--space-4);
}

.code code {
	border: 0;
	padding: 0;
	background: none;
}

.noscript {
	text-align: center;
	padding: var(--space-6);
}

/* ---------------------------------------------------------------- budget */

.period-nav {
	display: flex;
	align-items: center;
	gap: var(--space-2);
}

.period-label {
	display: flex;
	flex-direction: column;
	align-items: center;
	min-width: 190px;
	text-align: center;
	line-height: 1.3;
}

.period-title {
	font-weight: 650;
}

.period-hint {
	font-size: 0.78rem;
	color: var(--muted);
}

.summary .stats {
	display: grid;
	grid-template-columns: repeat(4, minmax(0, 1fr));
	gap: var(--space-4);
	margin-bottom: var(--space-4);
}

.stat-label {
	font-size: 0.8rem;
	font-weight: 600;
	color: var(--muted);
	text-transform: uppercase;
	letter-spacing: 0.04em;
}

.stat-value {
	font-size: 1.5rem;
	font-weight: 700;
	letter-spacing: -0.01em;
	line-height: 1.3;
}

.stat-extra {
	font-size: 0.85rem;
	color: var(--muted);
}

.stat.is-bad .stat-value,
.stat.is-bad .stat-extra {
	color: var(--bad);
}

.stat.is-good .stat-value {
	color: var(--ok);
}

.summary .meter {
	height: 8px;
}

.table-tools {
	display: flex;
	justify-content: flex-end;
	margin: 0 0 var(--space-2);
	font-size: 0.875rem;
	color: var(--muted);
}

/* ---------------------------------------------------------------- tables */

.table-scroll {
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
}

.card .table-scroll {
	box-shadow: none;
}

.table {
	width: 100%;
	border-collapse: separate;
	border-spacing: 0;
	font-size: 0.9rem;
}

.table th,
.table td {
	padding: 8px 12px;
	text-align: left;
	border-bottom: 1px solid var(--border);
	vertical-align: middle;
}

.table tbody tr:last-child > * {
	border-bottom: 0;
}

.table thead th {
	position: sticky;
	top: 0;
	background: var(--surface-2);
	color: var(--muted);
	font-size: 0.75rem;
	font-weight: 650;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	white-space: nowrap;
	z-index: 1;
}

.table tbody th {
	font-weight: 500;
}

.table .num {
	text-align: right;
	white-space: nowrap;
}

.table .center {
	text-align: center;
}

.table-compact th,
.table-compact td {
	padding: 6px 10px;
}

.table tbody tr:hover > * {
	background: color-mix(in srgb, var(--surface-2) 60%, var(--surface));
}

.budget-table {
	min-width: 1080px;
}

.sticky-col {
	position: sticky;
	left: 0;
	z-index: 2;
	background: var(--surface);
}

.table thead .sticky-col {
	z-index: 3;
	background: var(--surface-2);
}

.budget-table .name {
	padding-left: calc(12px + var(--depth, 0) * 18px);
	min-width: 200px;
	max-width: 280px;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	box-shadow: inset -1px 0 0 var(--border);
}

.row-category.depth-2 .name,
.row-category.depth-3 .name {
	color: var(--muted);
}

.row-category.depth-2 .name::before,
.row-category.depth-3 .name::before {
	content: '↳ ';
	opacity: 0.5;
}

.row-group > * {
	background: var(--surface-2);
	font-weight: 650;
	border-top: 1px solid var(--border-strong);
}

.row-group .name {
	text-transform: uppercase;
	letter-spacing: 0.04em;
	font-size: 0.8rem;
}

.budget-table tbody tr.row-group:hover > * {
	background: var(--surface-3);
}

/* Lines not counted in the overall budget (colour, not opacity: the name cell is sticky). */
.is-excluded .num,
.is-excluded .name {
	color: var(--muted);
}

.hide-empty .is-empty {
	display: none;
}

.budget-input {
	width: 110px;
	text-align: right;
	min-height: 32px;
	padding: 4px 8px;
	background: transparent;
	border-color: transparent;
	border-bottom: 1px dashed var(--border-strong);
	border-radius: 6px;
	transition:
		border-color 0.15s,
		background-color 0.15s;
}

.budget-input:hover,
.budget-input:focus {
	background: var(--surface);
	border: 1px solid var(--border-strong);
}

.budget-table select {
	min-height: 32px;
	padding: 4px 6px;
	font-size: 0.85rem;
}

.col-used {
	min-width: 120px;
}

.used {
	display: flex;
	align-items: center;
	gap: var(--space-2);
}

.used .meter {
	flex: 1;
	min-width: 50px;
	height: 5px;
}

.used-pct {
	font-size: 0.8rem;
	min-width: 3.2em;
	text-align: right;
}

/* ---------------------------------------------------------------- transactions */

.filters {
	display: flex;
	flex-wrap: wrap;
	align-items: flex-end;
	gap: 0 var(--space-4);
	padding-bottom: var(--space-2);
}

.filters .field-grow {
	flex: 1;
	min-width: 200px;
}

.filters .chips {
	margin-bottom: var(--space-4);
}

.result-bar {
	display: flex;
	flex-wrap: wrap;
	gap: var(--space-2) var(--space-5);
	margin: 0 0 var(--space-3);
	font-size: 0.9rem;
	color: var(--muted);
}

.result-bar strong {
	color: var(--text);
}

.result-bar .neg {
	color: var(--bad);
}

.tx-table .tx-category {
	min-width: 180px;
}

.tx-table .tx-note {
	color: var(--muted);
	min-width: 160px;
	max-width: 360px;
}

.fx-mark {
	color: var(--muted);
}

/* ---------------------------------------------------------------- cash flow */

.cf-list {
	display: flex;
	flex-direction: column;
	gap: var(--space-2);
}

.cf-item {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
}

.cf-item summary {
	display: grid;
	grid-template-columns: 1fr auto 8rem 4.5rem;
	align-items: center;
	gap: var(--space-4);
	padding: var(--space-3) var(--space-4);
	cursor: pointer;
	list-style: none;
}

.cf-item summary::-webkit-details-marker {
	display: none;
}

.cf-item summary::before {
	content: '›';
	position: absolute;
	margin-left: -12px;
	color: var(--muted);
	transition: transform 0.15s;
}

.cf-item[open] summary::before {
	transform: rotate(90deg);
}

.cf-item summary {
	position: relative;
	padding-left: calc(var(--space-4) + 12px);
}

.cf-period {
	display: flex;
	flex-direction: column;
}

.cf-closing {
	font-weight: 700;
	text-align: right;
}

.cf-change {
	text-align: right;
	font-weight: 600;
}

.cf-detail {
	padding: 0 var(--space-4) var(--space-3);
}

.cf-detail p {
	margin: var(--space-2) 0 0;
}

/* ---------------------------------------------------------------- brief */

.brief-grid {
	display: grid;
	grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
	gap: var(--space-4);
	align-items: start;
}

.brief-grid > .card {
	margin-bottom: 0;
}

.wa-chat {
	background: var(--wa-bg);
	border-radius: var(--radius-sm);
	padding: var(--space-4);
	margin-bottom: var(--space-3);
}

.wa-bubble {
	position: relative;
	max-width: 440px;
	background: var(--wa-bubble);
	color: var(--wa-text);
	border-radius: 8px 0 8px 8px;
	padding: 8px 10px 20px;
	margin-left: auto;
	box-shadow: 0 1px 0.5px rgb(11 20 26 / 0.13);
}

.wa-bubble::after {
	content: '';
	position: absolute;
	top: 0;
	right: -8px;
	border-left: 8px solid var(--wa-bubble);
	border-bottom: 10px solid transparent;
}

.wa-text {
	white-space: pre-wrap;
	overflow-wrap: anywhere;
	font-size: 0.92rem;
	line-height: 1.45;
}

.wa-time {
	position: absolute;
	right: 10px;
	bottom: 4px;
	font-size: 0.7rem;
	opacity: 0.6;
}

.params-table td {
	overflow-wrap: anywhere;
}

.recipients {
	list-style: none;
	margin: var(--space-2) 0 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: 4px;
}

.recipients li {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--space-2);
}

.recipients .error-text {
	flex-basis: 100%;
}

.unmatched {
	margin-top: var(--space-2);
	font-size: 0.85rem;
}

.unmatched ul {
	max-height: 220px;
	overflow: auto;
	margin: var(--space-2) 0 0;
	padding-left: 1.2em;
}

/* ---------------------------------------------------------------- settings */

.settings-grid,
.admin-grid {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
	gap: 0 var(--space-4);
	align-items: start;
}

.settings-form .button-row {
	margin-top: var(--space-2);
}

.tabs {
	display: flex;
	gap: var(--space-1);
	border-bottom: 1px solid var(--border);
	margin-bottom: var(--space-3);
}

.tab {
	font: inherit;
	font-weight: 550;
	background: none;
	border: 0;
	border-bottom: 2px solid transparent;
	padding: 8px 12px;
	margin-bottom: -1px;
	color: var(--muted);
	cursor: pointer;
}

.tab[aria-selected='true'] {
	color: var(--accent);
	border-bottom-color: var(--accent);
}

.logs-scroll {
	max-height: 520px;
	overflow: auto;
}

.log-message {
	min-width: 280px;
	overflow-wrap: anywhere;
	white-space: pre-wrap;
}

/* ---------------------------------------------------------------- setup wizard */

.wizard {
	max-width: 780px;
	margin: 0 auto;
}

.wizard-head {
	margin-bottom: var(--space-5);
}

.wizard-head p {
	margin: 4px 0 0;
}

.stepper {
	display: flex;
	list-style: none;
	margin: 0 0 var(--space-5);
	padding: 0;
	counter-reset: step;
}

.stepper li {
	flex: 1;
	position: relative;
}

.stepper li + li::before {
	content: '';
	position: absolute;
	top: 15px;
	right: calc(50% + 20px);
	left: calc(-50% + 20px);
	height: 2px;
	background: var(--border-strong);
}

.stepper li.done + li::before,
.stepper li.done::before {
	background: var(--accent);
}

.stepper a {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 6px;
	color: var(--muted);
	text-decoration: none;
	font-size: 0.85rem;
	font-weight: 550;
}

.step-num {
	display: grid;
	place-items: center;
	width: 32px;
	height: 32px;
	border-radius: 50%;
	border: 2px solid var(--border-strong);
	background: var(--surface);
	font-weight: 700;
}

.stepper .done .step-num {
	background: var(--accent);
	border-color: var(--accent);
	color: var(--accent-text);
}

.stepper .current a {
	color: var(--text);
}

.stepper .current .step-num {
	border-color: var(--accent);
	color: var(--accent);
	box-shadow: 0 0 0 4px var(--accent-soft);
}

.wizard-footer {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: var(--space-3);
	margin-top: var(--space-5);
}

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

.check {
	display: flex;
	gap: var(--space-3);
	padding: var(--space-3) 0;
	border-top: 1px solid var(--border);
}

.check:first-child {
	border-top: 0;
}

.check-icon {
	flex: none;
	display: grid;
	place-items: center;
	width: 24px;
	height: 24px;
	border-radius: 50%;
	font-size: 0.8rem;
	font-weight: 800;
}

.check-icon.ok {
	background: var(--ok-soft);
	color: var(--ok);
}

.check-icon.bad {
	background: var(--bad-soft);
	color: var(--bad);
}

.check-icon.off {
	background: var(--surface-2);
	color: var(--muted);
}

.check-label {
	font-weight: 600;
}

/* ---------------------------------------------------------------- households: header, signup, owner console */

.household-pill {
	font-size: 0.82rem;
	font-weight: 600;
	color: var(--accent);
	background: var(--accent-soft);
	border-radius: 999px;
	padding: 3px 10px;
	white-space: nowrap;
	max-width: 14em;
	overflow: hidden;
	text-overflow: ellipsis;
}

.screen-foot {
	margin: var(--space-4) 0 0;
	text-align: center;
}

.screen-card .field-error[role='alert']:not(:empty) {
	margin-top: var(--space-2);
}

.turnstile-box {
	min-height: 65px; /* the Turnstile widget's height: no layout jump when it appears */
	display: flex;
	align-items: center;
}

.steps-list {
	margin: 0 0 var(--space-3);
	padding-left: 1.3em;
}

.select-sm {
	min-height: 30px;
	padding: 3px 8px;
	font-size: 0.85rem;
}

.owner-table td,
.owner-table th {
	vertical-align: top;
}

.owner-name {
	font-weight: 600;
}

.owner-table .is-suspended > * {
	opacity: 0.7;
}

.owner-sync-msg {
	max-width: 260px;
	overflow-wrap: anywhere;
}

.owner-actions {
	flex-wrap: nowrap;
}

.key-dot {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	color: var(--muted);
}

.key-dot .dot {
	width: 8px;
	height: 8px;
	border-radius: 50%;
	border: 1.5px solid var(--border-strong);
}

.key-dot.is-on {
	color: var(--text);
}

.key-dot.is-on .dot {
	background: var(--ok);
	border-color: var(--ok);
}

.dialog {
	width: min(420px, calc(100vw - 2 * var(--space-4)));
	color: var(--text);
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 16px;
	box-shadow: var(--shadow-lg);
	padding: var(--space-5);
}

.dialog::backdrop {
	background: rgb(0 0 0 / 0.45);
}

.dialog .field {
	margin-top: var(--space-3);
}

.dialog-actions {
	justify-content: flex-end;
	margin-top: var(--space-4);
}

/* ---------------------------------------------------------------- responsive */

@media (max-width: 900px) {
	.topbar-inner {
		flex-wrap: wrap;
		gap: 0 var(--space-3);
		padding-top: var(--space-2);
	}

	.nav {
		order: 3;
		flex-basis: 100%;
		overflow-x: auto;
		scrollbar-width: none;
		padding: var(--space-1) 0 var(--space-2);
		margin: 0 calc(-1 * var(--space-4));
		padding-inline: var(--space-4);
	}

	.nav::-webkit-scrollbar {
		display: none;
	}

	.topbar-end {
		margin-left: auto;
	}

	.brief-grid {
		grid-template-columns: minmax(0, 1fr);
	}

	.summary .stats {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}
}

@media (max-width: 480px) {
	body {
		font-size: 14px;
	}

	main {
		padding: var(--space-4) var(--space-3) 48px;
	}

	h1 {
		font-size: 1.35rem;
	}

	.brand-name,
	.period-pill {
		display: none;
	}

	.household-pill {
		max-width: 9em;
	}

	.card {
		padding: var(--space-4);
	}

	.page-header {
		align-items: stretch;
	}

	.period-nav {
		width: 100%;
		justify-content: space-between;
	}

	.period-label {
		min-width: 0;
		flex: 1;
	}

	.stat-value {
		font-size: 1.2rem;
	}

	.budget-table .name {
		min-width: 140px;
		max-width: 160px;
	}

	.settings-grid,
	.admin-grid {
		grid-template-columns: minmax(0, 1fr);
	}

	.cf-item summary {
		grid-template-columns: 1fr auto;
		gap: 2px var(--space-3);
	}

	.cf-item summary .badge {
		display: none;
	}

	.step-title {
		font-size: 0.75rem;
	}

	.wizard-footer {
		flex-direction: column-reverse;
		align-items: stretch;
	}

	.wizard-footer .button-row {
		flex-direction: column;
		align-items: stretch;
	}

	.screen-card {
		padding: var(--space-5);
	}

	.meter-legend span:last-child {
		display: none;
	}
}

@media (prefers-reduced-motion: reduce) {
	*,
	*::before,
	*::after {
		animation-duration: 0.01ms !important;
		transition-duration: 0.01ms !important;
		scroll-behavior: auto !important;
	}
}
