/* Miti's styles. Written for a phone first: one column, big tap targets, and
   text that doesn't need zooming. Wider screens just get more margin. */

:root {
	/* Lets the browser draw its own controls (checkboxes, radios, date
	   pickers, scrollbars) dark when the page is dark. */
	color-scheme: light dark;
	--text: #1d2433;
	--muted: #5d667a;
	--background: #f6f7f9;
	--surface: #ffffff;
	--border: #d9dde5;
	--accent: #1f6feb;
	--accent-text: #ffffff;
	--danger: #b42318;
	--warning-background: #fdecea;
	--owed: #1a7f37;
	--owes: #b42318;
}

@media (prefers-color-scheme: dark) {
	:root {
		--text: #e8eaf0;
		--muted: #a2a9ba;
		--background: #12151c;
		--surface: #1b1f29;
		--border: #333a4a;
		--accent: #6ea8ff;
		--accent-text: #0b1220;
		--danger: #ff8a80;
		--warning-background: #3a1d1b;
		--owed: #5fd07b;
		--owes: #ff8a80;
	}
}

* {
	box-sizing: border-box;
}

body {
	margin: 0;
	background: var(--background);
	color: var(--text);
	font: 1rem/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

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

.site-header {
	display: flex;
	flex-wrap: nowrap;
	align-items: center;
	justify-content: space-between;
	gap: 0.5rem 1rem;
	padding: 0.5rem 1rem;
	background: var(--surface);
	border-bottom: 1px solid var(--border);
}

.brand {
	font-size: 1.25rem;
	font-weight: 700;
	text-decoration: none;
	color: var(--text);
}

.site-header nav {
	display: flex;
	gap: 0.875rem;
}

.site-header nav a {
	padding: 0.5rem 0;
	text-decoration: none;
	border-bottom: 2px solid transparent;
}

/* The current page, or the section the page is in. */
.site-header nav a[aria-current] {
	color: var(--text);
	font-weight: 600;
	border-bottom-color: var(--accent);
}

main {
	max-width: 44rem;
	margin: 0 auto;
	padding: 1rem;
}

h1 {
	font-size: 1.6rem;
	line-height: 1.25;
	margin: 0.5rem 0 1rem;
}

h2 {
	font-size: 1.2rem;
	margin: 2rem 0 0.5rem;
}

h3 {
	font-size: 1.05rem;
	margin: 1.25rem 0 0.5rem;
}

/* Lists of things are cards, which are easy to tell apart and to tap. */
main ul {
	list-style: none;
	padding: 0;
	margin: 0.5rem 0 1rem;
}

main ul > li {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 0.5rem;
	padding: 0.75rem 1rem;
	margin-bottom: 0.5rem;
}

/* A card that is one big link, like an expense in a list. */
main ul > li.card {
	padding: 0;
}

.card-link {
	display: block;
	padding: 0.75rem 1rem;
	color: inherit;
	text-decoration: none;
	border-radius: 0.5rem;
}

.card-link:hover,
.card-link:focus-visible {
	background: var(--background);
}

.card-link > span {
	display: block;
}

.card-title {
	font-weight: 600;
	color: var(--accent);
}

/* A payment sits among the expense cards. It isn't a link, so its title is
   plain text, and a stripe in the "settled" colour tells it apart at a glance;
   the words "Payment" say so too, for anyone who can't see the colour. */
main ul > li.card.payment {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	padding: 0.75rem 1rem;
	border-left: 4px solid var(--owed);
}

.payment-body {
	flex: 1;
	min-width: 0;
}

.payment-body > span {
	display: block;
	overflow-wrap: anywhere;
}

.payment-title {
	font-weight: 600;
}

.payment-undo {
	flex-shrink: 0;
	padding: 0.5rem 0;
}

/* A list inside a card is plain. */
main li ul {
	margin: 0.5rem 0 0;
}

main li li {
	border: 0;
	border-radius: 0;
	padding: 0.25rem 0;
	margin: 0;
	background: none;
}

/* Wide tables scroll sideways inside themselves instead of the whole page. */
table {
	display: block;
	max-width: 100%;
	overflow-x: auto;
	border-collapse: collapse;
	margin: 0.5rem 0 1rem;
}

th, td {
	padding: 0.5rem 0.75rem;
	text-align: left;
	border-bottom: 1px solid var(--border);
	white-space: nowrap;
}

th {
	color: var(--muted);
	font-weight: 600;
	font-size: 0.9rem;
}

details {
	margin-top: 0.5rem;
}

summary {
	cursor: pointer;
	padding: 0.5rem 0;
	color: var(--accent);
}

/* A fieldset is normally at least as wide as its content, so a wide table
   inside one would push the page sideways; min-width: 0 lets the table scroll
   inside it instead. */
fieldset {
	min-width: 0;
	border: 1px solid var(--border);
	border-radius: 0.5rem;
	margin: 1rem 0;
	padding: 0.5rem 1rem 1rem;
}

legend {
	padding: 0 0.5rem;
	font-weight: 600;
}

/* Forms. Inputs are 16px or more so phones don't zoom in when you tap them. */
label {
	display: block;
	margin: 0.75rem 0 0.25rem;
	font-weight: 600;
}

fieldset label {
	font-weight: 400;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="search"],
select,
textarea {
	width: 100%;
	min-height: 2.75rem;
	padding: 0.5rem 0.75rem;
	font: inherit;
	color: var(--text);
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 0.5rem;
}

/* A textarea takes the whole line, so the button after it goes underneath. */
textarea {
	display: block;
	min-height: 6rem;
	margin-bottom: 0.75rem;
	resize: vertical;
}

td input[type="text"] {
	min-width: 6rem;
}

input[type="checkbox"],
input[type="radio"] {
	width: 1.25rem;
	height: 1.25rem;
	margin-right: 0.5rem;
	vertical-align: middle;
}

button,
.button {
	display: inline-block;
	min-height: 2.75rem;
	padding: 0.5rem 1.25rem;
	font: inherit;
	font-weight: 600;
	color: var(--accent-text);
	background: var(--accent);
	border: 0;
	border-radius: 0.5rem;
	cursor: pointer;
	text-decoration: none;
}

/* A second button next to the main one: same size, less weight. */
.button.secondary,
button.secondary {
	color: var(--accent);
	background: transparent;
	border: 1px solid var(--accent);
}

/* A row of the page's main actions, which wraps on a narrow screen. */
.actions {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.5rem 1rem;
}

/* A search box with its button beside it. */
.search {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.5rem;
	margin-bottom: 0.5rem;
}

.search label {
	flex-basis: 100%;
	margin: 0;
}

.search input {
	flex: 1;
	min-width: 10rem;
}

.summary {
	font-size: 1.1rem;
	margin: 0 0 0.75rem;
}

button.link {
	min-height: 0;
	padding: 0.5rem 0;
	font-weight: 400;
	color: var(--accent);
	background: transparent;
}

/* Buttons that undo or remove something look less inviting. A link-style
   button stays a link, even when it deletes something. */
form[action$="/delete"] button:not(.link),
button.danger,
.button.danger {
	color: var(--danger);
	background: transparent;
	border: 1px solid var(--danger);
}

li form {
	display: inline;
}

li button {
	min-height: 2.25rem;
	padding: 0.25rem 0.75rem;
	font-weight: 400;
}

/* Keeps the line breaks a note was written with. */
.note-body {
	margin: 0.25rem 0;
	white-space: pre-line;
}

/* "Saved" messages, and other news about what you just did. */
[role="status"] {
	padding: 0.75rem 1rem;
	background: var(--surface);
	border: 1px solid var(--owed);
	border-left-width: 0.375rem;
	border-radius: 0.5rem;
}

[role="alert"] {
	padding: 0.75rem 1rem;
	color: var(--danger);
	background: var(--warning-background);
	border: 1px solid var(--danger);
	border-radius: 0.5rem;
}

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

/* Money from the viewer's side. The words always say which way it goes, so
   colour is never the only signal. */
.owed {
	color: var(--owed);
}

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

input[readonly] {
	background: var(--background);
}

/* The hidden attribute wins over display rules like .button's. */
[hidden] {
	display: none !important;
}

@media (min-width: 40rem) {
	input[type="text"],
	input[type="email"],
	input[type="password"],
	input[type="date"],
	select {
		max-width: 28rem;
	}

	.site-header {
		padding: 0.5rem max(1rem, calc((100% - 44rem) / 2 + 1rem));
	}
}

/* A category's icon on a rounded badge, coloured by its top-level category
   (D19). The icon's strokes follow the text colour, so each pair below is a
   light-on-dark or dark-on-light one chosen to read at 3:1 or better: the
   lowest is 4.5:1 in light mode and 6.3:1 in dark. */
.category-badge {
	--badge-background: #e5e7eb;
	--badge-icon: #4b5563;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex: none;
	width: 2.25rem;
	height: 2.25rem;
	border-radius: 0.5rem;
	background: var(--badge-background);
	color: var(--badge-icon);
	vertical-align: middle;
}

.category-entertainment { --badge-background: #f3e8ff; --badge-icon: #7e22ce; }
.category-food-and-drink { --badge-background: #ffedd5; --badge-icon: #c2410c; }
.category-home { --badge-background: #dbeafe; --badge-icon: #1d4ed8; }
.category-life { --badge-background: #fce7f3; --badge-icon: #be185d; }
.category-transportation { --badge-background: #cffafe; --badge-icon: #0e7490; }
.category-uncategorized { --badge-background: #e5e7eb; --badge-icon: #4b5563; }
.category-utilities { --badge-background: #fef9c3; --badge-icon: #854d0e; }

@media (prefers-color-scheme: dark) {
	.category-entertainment { --badge-background: #3b1f5c; --badge-icon: #d8b4fe; }
	.category-food-and-drink { --badge-background: #4a2410; --badge-icon: #fdba74; }
	.category-home { --badge-background: #1e3a8a; --badge-icon: #bfdbfe; }
	.category-life { --badge-background: #5b1a3a; --badge-icon: #f9a8d4; }
	.category-transportation { --badge-background: #164e63; --badge-icon: #67e8f9; }
	.category-uncategorized { --badge-background: #374151; --badge-icon: #d1d5db; }
	.category-utilities { --badge-background: #4a3a0a; --badge-icon: #fde047; }
}

/* An expense's card: the badge beside the text. */
.card-link > .expense-row {
	display: flex;
	align-items: flex-start;
	gap: 0.75rem;
}

.expense-body {
	flex: 1;
	min-width: 0;
}

.expense-body > span {
	display: block;
}

/* The badge beside a heading, and the one beside the Category select. */
.heading-with-badge {
	display: flex;
	align-items: center;
	gap: 0.75rem;
}

.heading-with-badge > h1 {
	margin: 0.75rem 0;
	min-width: 0;
	overflow-wrap: anywhere;
}

.category-field {
	display: flex;
	align-items: center;
	gap: 0.75rem;
}

.category-field select {
	flex: 1;
	min-width: 0;
}
