/* The ui-* components (TagHelpers/) and the shared pieces pages build with, loaded on every page by
   Views/Shared/_Layout.cshtml. Pages only place components (grid-area, margins); how they look
   lives here, in the tokens of css/tokens.css. */

/* ---- Text input and select (class="input"; the page adds layout such as grid-area) ---- */

.input {
	box-sizing: border-box;
	height: var(--h-md);
	padding: 0 var(--s-3);
	font-size: var(--fs-md);
	border: 1px solid var(--border);
	border-radius: var(--r-md);
	background: Canvas;
	color: CanvasText;
}

select.input {
	padding-right: var(--s-1);
}

textarea.input {
	height: auto;
	padding-block: var(--s-2);
}

/* A shorter field, for lists of rows. */
.input.compact {
	height: var(--h-sm);
	padding-block: 0;
}

/* A field in a row that saves as you go: reads as text until hovered or focused. */
.input.quiet:not(:hover, :focus) {
	border-color: transparent;
	background: transparent;
}

/* Right-aligned figures in a field. */
.input.amount {
	text-align: right;
	font-variant-numeric: tabular-nums;
}

/* ---- Buttons: <ui-button>, <ui-delete-button> ---- */

.btn {
	box-sizing: border-box;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: var(--s-2);
	height: var(--h-md);
	padding: 0 var(--s-5);
	font: inherit;
	font-size: var(--fs-md);
	font-weight: 600;
	border: 1px solid transparent;
	border-radius: var(--r-md);
	text-decoration: none;
	cursor: pointer;
}

.btn:focus-visible {
	outline: 3px solid var(--focus-ring);
	outline-offset: 2px;
}

.btn:active:not(:disabled) {
	transform: scale(0.97);
}

.btn:disabled {
	opacity: var(--o-faint);
	cursor: default;
}

.btn-primary {
	background: var(--c-primary);
	color: var(--on-primary);
}

.btn-primary.btn-danger {
	background: var(--c-danger);
}

@media (hover: hover) {
	.btn-primary:hover:not(:disabled) {
		filter: brightness(1.08);
	}
}

.btn-outline {
	border-color: var(--border);
	background: Canvas;
	color: inherit;
	font-weight: 400;
}

.btn-icon {
	width: var(--h-md);
	padding: 0;
	border-color: var(--border-soft);
	background: Canvas;
	color: inherit;
	font-weight: 400;
}

.btn-outline.btn-danger,
.btn-icon.btn-danger {
	color: var(--c-danger);
}

.btn-sm {
	height: var(--h-sm);
	padding: 0 var(--s-4);
	font-size: var(--fs-sm);
}

.btn-icon.btn-sm {
	width: var(--h-sm);
	padding: 0;
}

.btn-lg {
	height: var(--h-lg);
	font-size: var(--fs-lg);
}

.btn-block {
	display: flex;
	width: 100%;
}

/* ---- Notice: <ui-notice> ---- */

.notice {
	padding: var(--s-3) var(--s-5);
	border-radius: var(--r-md);
	font-weight: 600;
}

.notice-ok {
	background: var(--c-ok-bg);
	color: var(--c-ok);
}

.notice-error {
	background: var(--c-danger-bg);
	color: var(--c-danger);
}

/* ---- Money: <ui-money> ---- */

.money {
	font-variant-numeric: tabular-nums;
	white-space: nowrap;
}

.money.neg {
	color: var(--c-danger);
}

.money.zero {
	opacity: var(--o-faint);
}

/* ---- Progress bar: <ui-progress> ---- */

.progress {
	position: relative;
	display: block;
	height: 0.7rem;
	border-radius: var(--r-pill);
	background: var(--fill);
	overflow: hidden;
}

.progress .fill {
	display: block;
	height: 100%;
	border-radius: inherit;
	background: var(--c-ok);
}

.progress.over .fill {
	background: var(--c-danger);
}

/* Where the spending "should" be by today: a thin line across the bar. */
.progress .pace {
	position: absolute;
	top: 0;
	bottom: 0;
	width: 2px;
	margin-left: -1px;
	background: CanvasText;
	opacity: var(--o-muted);
}

/* ---- Boxes ---- */

/* A card with a soft border: categories, budget and progress groups, the sign-in form. */
.card {
	padding: var(--s-4);
	border: 1px solid var(--border-soft);
	border-radius: var(--r-lg);
	background: Canvas;
}

/* A tinted panel for a page's figures: budget totals, progress summaries. */
.panel {
	padding: var(--s-4) var(--s-5);
	border-radius: var(--r-lg);
	background: var(--fill-faint);
}

/* A dashed box around a form that adds something (and the transaction form). Pages lay out its fields. */
.add-box {
	border: 1px dashed var(--border);
	border-radius: var(--r-lg);
}

/* ---- Data table: <table class="data-table"> (accounts, register, progress detail) ----
   A real table, so headings always sit over their columns. Sortable headings hold a button
   (.sort) with aria-sort on the <th>. Numbers: class="num" on th and td. */

.data-table {
	width: 100%;
	border-collapse: collapse;
	font-size: var(--fs-sm);
}

.data-table th,
.data-table td {
	padding: var(--s-2) var(--s-3);
	border-bottom: 1px solid var(--border-soft);
	text-align: left;
	vertical-align: middle;
}

.data-table thead th {
	position: sticky;
	top: 0;
	z-index: 1;
	border-bottom: 2px solid var(--border);
	background: Canvas;
	font-size: var(--fs-xs);
	font-weight: 700;
	letter-spacing: 0.03em;
	text-transform: uppercase;
	white-space: nowrap;
	opacity: var(--o-soft);
}

.data-table .num {
	text-align: right;
	white-space: nowrap;
	font-variant-numeric: tabular-nums;
}

.data-table tbody tr:hover > td {
	background: var(--fill-hover);
}

.data-table tfoot td {
	border-bottom: 0;
	font-weight: 700;
}

/* A sortable heading (a table's, or a .list-head's): the whole heading is the button; the arrow shows the current order. */
:is(.data-table, .list-head) .sort {
	display: inline-flex;
	align-items: center;
	gap: var(--s-1);
	padding: 0;
	border: 0;
	background: none;
	color: inherit;
	font: inherit;
	letter-spacing: inherit;
	text-transform: inherit;
	cursor: pointer;
}

:is(.data-table, .list-head) .sort::after {
	content: "↕";
	opacity: var(--o-faint);
}

:is(.data-table, .list-head) [aria-sort="ascending"] .sort::after {
	content: "↑";
	opacity: 1;
}

:is(.data-table, .list-head) [aria-sort="descending"] .sort::after {
	content: "↓";
	opacity: 1;
}

:is(.data-table, .list-head) .sort:hover {
	color: var(--c-primary);
}

/* Inputs inside cells fill them. */
.data-table td > .input {
	width: 100%;
	min-width: 0;
	box-sizing: border-box;
}

/* ---- Editable lists (categories, payees, budget) ---- */

/* The heading over a list: its h2, and quieter notes or column names beside it. Pages lay it out. */
.list-head {
	padding: 0 var(--s-3) var(--s-1);
	border-bottom: 2px solid var(--border);
}

.list-head h2 {
	margin: 0;
	font-size: var(--fs-lg);
}

.list-head span {
	font-size: var(--fs-xs);
	opacity: var(--o-muted);
}

/* How many transactions use a record (it can't be deleted while any do). */
.use-count {
	justify-self: center;
	min-width: 2rem;
	padding: 0 var(--s-1);
	border-radius: var(--r-pill);
	background: var(--fill);
	font-size: var(--fs-xs);
	line-height: 1.5rem;
	text-align: center;
}

/* A small outlined label beside some text ("refund", "split"). Pages pick its colour. */
.tag {
	margin-left: var(--s-1);
	padding: 0 var(--s-2);
	border: 1px solid currentColor;
	border-radius: var(--r-pill);
	font-size: var(--fs-xs);
	font-weight: 400;
}

/* A subcategory's bucket (<ui-bucket>): a tinted pill in the bucket's hue, its text mixed toward
   the page's text colour so it reads in light and dark mode. */
.bucket-tag {
	display: inline-block;
	padding: 0 var(--s-2);
	border-radius: var(--r-pill);
	font-size: var(--fs-xs);
	font-weight: 600;
	line-height: 1.6;
	white-space: nowrap;

	&.recurring {
		color: color-mix(in srgb, var(--c-bucket-recurring) 75%, CanvasText);
		background: color-mix(in srgb, var(--c-bucket-recurring) 14%, Canvas);
	}

	&.exceptional {
		color: color-mix(in srgb, var(--c-bucket-exceptional) 75%, CanvasText);
		background: color-mix(in srgb, var(--c-bucket-exceptional) 14%, Canvas);
	}

	&.reimbursement {
		color: color-mix(in srgb, var(--c-bucket-reimbursement) 75%, CanvasText);
		background: color-mix(in srgb, var(--c-bucket-reimbursement) 14%, Canvas);
	}

	&.financial {
		color: color-mix(in srgb, var(--c-bucket-financial) 75%, CanvasText);
		background: color-mix(in srgb, var(--c-bucket-financial) 14%, Canvas);
	}

	&.personal-fund {
		color: color-mix(in srgb, var(--c-bucket-personal-fund) 75%, CanvasText);
		background: color-mix(in srgb, var(--c-bucket-personal-fund) 14%, Canvas);
	}
}

/* A totals card (Views/Shared/_TotalCards): a .panel with a coloured top edge (its bucket's) and a
   small table: label, budget, YTD, remaining. Pages lay the cards out. */
.total-card {
	border-top: 3px solid var(--border);

	h3 {
		margin: 0 0 var(--s-3);
		font-size: var(--fs-md);
	}

	table {
		width: 100%;
		border-collapse: collapse;
	}

	th,
	td {
		padding: var(--s-1) 0;
	}

	thead th {
		font-size: var(--fs-xs);
		font-weight: 400;
		opacity: var(--o-muted);
	}

	thead th,
	td {
		padding-left: var(--s-4);
		text-align: right;
		white-space: nowrap;
	}

	tbody th {
		font-weight: 400;
		text-align: left;
	}

	.net {
		font-weight: 700;

		th,
		td {
			padding-top: var(--s-2);
			border-top: 1px solid var(--border-soft);
		}
	}

	/* A bucket's part of the line above (Recurring, Exceptional): indented, smaller. */
	.part {
		font-size: var(--fs-sm);

		th {
			padding-left: var(--s-4);
		}
	}

	.note {
		margin: var(--s-2) 0 0;
		font-size: var(--fs-xs);
		opacity: var(--o-muted);
	}

	/* All activity: three figures (income, expenses, net) spread evenly across the card, centred,
	   each its YTD large with its budget under it; stacked when narrow. */
	.stats {
		display: grid;
		grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
		gap: var(--s-4);
		margin: var(--s-2) 0;
	}

	.stat {
		display: grid;
		justify-items: center;
		gap: var(--s-0);
		text-align: center;

		.label {
			font-size: var(--fs-sm);
			opacity: var(--o-muted);
		}

		.figure {
			font-size: var(--fs-xl);
			font-weight: 700;
		}

		.detail {
			font-size: var(--fs-sm);
			opacity: var(--o-muted);
		}
	}

	table.phone-only {
		display: none;
	}

	&.all h3,
	&.all .note {
		text-align: center;
	}

	/* Phones: tighter, smaller figures so the four columns fit; All activity swaps its big figures
	   for the same table as the other cards. */
	@container (max-width: 40rem) {
		padding: var(--s-3);

		table {
			font-size: var(--fs-sm);
		}

		thead th,
		td {
			padding-left: var(--s-2);
		}

		.part th {
			padding-left: var(--s-2);
		}

		.stats {
			display: none;
		}

		table.phone-only {
			display: table;
		}

		&.all h3,
		&.all .note {
			text-align: left;
		}
	}

	&.ordinary { border-top-color: var(--c-bucket-recurring); }
	&.reimbursement { border-top-color: var(--c-bucket-reimbursement); }
	&.financial { border-top-color: var(--c-bucket-financial); }
	&.personal-fund { border-top-color: var(--c-bucket-personal-fund); }
	&.all,
	&.all-up { border-top-color: var(--c-primary); }
}

/* A link that reads as the text it wraps until hovered (a balance, an actual). */
.quiet-link {
	color: inherit;
	text-decoration: none;
}

.quiet-link:hover {
	text-decoration: underline;
}

/* ---- Suggestions under a payee or category field (site.js: a combobox over a <datalist>) ---- */

.suggest {
	position: absolute;
	z-index: 10;
	box-sizing: border-box;
	max-width: min(28rem, 95vw);
	max-height: 18rem;
	overflow-y: auto;
	list-style: none;
	margin: var(--s-0) 0 0;
	padding: var(--s-1);
	border: 1px solid var(--border);
	border-radius: var(--r-md);
	background: Canvas;
	color: CanvasText;
	box-shadow: var(--shadow-lifted);
	font-size: var(--fs-md);

	li {
		display: flex;
		justify-content: space-between;
		gap: var(--s-4);
		padding: var(--s-1) var(--s-3);
		border-radius: var(--r-sm);
		white-space: nowrap;
		cursor: pointer;

		&:hover {
			background: var(--fill-hover);
		}

		/* The choice Tab or Enter takes. */
		&[aria-selected="true"] {
			background: var(--c-primary-bg);
		}
	}

	.note {
		font-size: var(--fs-sm);
		opacity: var(--o-muted);
	}
}

/* ---- A round on/off toggle with a check (the register's cleared toggle, _Cleared) ---- */

.check-toggle {
	box-sizing: border-box;
	display: inline-grid;
	place-items: center;
	width: 1.6rem;
	height: 1.6rem;
	padding: 0;
	border: 1px solid var(--border);
	border-radius: var(--r-pill);
	background: none;
	color: transparent; /* the check shows only when on, or faintly on hover */
	font: inherit;
	font-size: var(--fs-sm);
	font-weight: 700;
	line-height: 1;
	cursor: pointer;

	&:hover {
		border-color: var(--c-ok);
		color: var(--c-ok);
	}

	&:focus-visible {
		outline: 2px solid var(--focus-ring);
		outline-offset: 1px;
	}

	&.on {
		border-color: var(--c-ok);
		background: var(--c-ok);
		color: var(--on-primary);
	}
}
