/* Global styles and the pieces used on many pages; the values come from css/tokens.css.
   Each page adds its own stylesheet (css/<page>.css) for its layout; components are in css/ui.css. */

body {
	margin: 0;
	font-family: system-ui, sans-serif;
	background: Canvas;
	color: CanvasText;
}

a {
	color: var(--c-link);
}

/* Instant taps on touch screens, no grey flash */
button,
a {
	touch-action: manipulation;
	-webkit-tap-highlight-color: transparent;
}

/* Visually hidden, still read by screen readers */
.sr {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
}

/* Lets a <form> wrap controls without breaking its parent's grid */
.contents {
	display: contents;
}

/* The page's error line (#page-error). */
.error {
	position: sticky;
	top: var(--s-3);
	z-index: 1;
	padding: var(--s-3) var(--s-5);
	border-radius: var(--r-md);
	background: var(--c-danger-bg);
	color: var(--c-danger);
	font-weight: 600;
}

.error:empty {
	display: none;
}

/* ---- App shell (Views/Shared/_Layout.cshtml): sidebar on the left, the page beside it ---- */

.app-shell {
	display: grid;
	grid-template-columns: 15rem minmax(0, 1fr);
	min-height: 100vh;
}

.app-content {
	min-width: 0;
}

.sidebar {
	position: sticky;
	top: 0;
	display: flex;
	flex-direction: column;
	gap: var(--s-5);
	box-sizing: border-box;
	height: 100vh;
	overflow-y: auto;
	padding: var(--s-5) var(--s-4);
	background: var(--c-primary);
	color: var(--on-primary);
}

.sidebar a {
	color: inherit;
	text-decoration: none;
}

.sidebar a:focus-visible,
.sidebar button:focus-visible {
	outline: 3px solid var(--on-primary);
	outline-offset: 2px;
}

.brand {
	padding: 0 var(--s-3);
	font-size: var(--fs-lg);
	font-weight: 700;
	letter-spacing: 0.01em;
}

/* The sidebar's small uppercase headings: "Accounts", "Year". */
.side-accounts summary,
.year-label {
	font-size: var(--fs-xs);
	font-weight: 700;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	opacity: var(--o-muted);
}

/* The page links, and Import / export and Sign out at the foot (styled the same). */
.side-nav,
.side-foot {
	display: grid;
	gap: var(--s-0);
}

.side-nav a,
.side-foot a,
.side-foot button {
	display: block;
	padding: var(--s-2) var(--s-3);
	border-radius: var(--r-md);
	font-weight: 600;
	opacity: var(--o-soft);
}

.side-nav a:hover,
.side-nav a.here,
.side-foot a:hover,
.side-foot a.here,
.side-foot button:hover,
.side-foot button:focus-visible {
	background: var(--on-primary-fill);
	opacity: 1;
}

/* The year's accounts with balances (Views/Shared/Components/SidebarAccounts). */
.side-accounts {
	border-top: 1px solid var(--on-primary-line);
	padding-top: var(--s-4);
}

.side-accounts summary {
	padding: 0 var(--s-3) var(--s-2);
	list-style: none;
}

.side-accounts summary::-webkit-details-marker {
	display: none;
}

.side-account-list {
	display: grid;
	gap: var(--s-0);
	margin: 0;
	padding: 0;
	list-style: none;
}

.side-account-list a {
	display: flex;
	justify-content: space-between;
	align-items: baseline;
	gap: var(--s-3);
	padding: var(--s-2) var(--s-3);
	border-radius: var(--r-sm);
	font-size: var(--fs-sm);
}

.side-account-list a:hover,
.side-account-list a.here {
	background: var(--on-primary-fill);
}

.side-name {
	min-width: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

/* Negative balances get a pale red, not the page's red. */
.sidebar .money {
	color: inherit;
	white-space: nowrap;
}

.sidebar .money.neg {
	color: var(--on-primary-neg);
}

.side-total {
	display: flex;
	justify-content: space-between;
	margin: var(--s-2) 0 0;
	padding: var(--s-2) var(--s-3) 0;
	border-top: 1px solid var(--on-primary-line);
	font-size: var(--fs-sm);
	font-weight: 700;
}

.side-empty {
	margin: 0;
	padding: 0 var(--s-3);
	font-size: var(--fs-sm);
}

.side-empty a {
	text-decoration: underline;
}

/* Pinned to the bottom of the sidebar. */
.side-foot {
	margin-top: auto;
	padding-top: var(--s-4);
	border-top: 1px solid var(--on-primary-line);
}

.side-foot button {
	width: 100%;
	box-sizing: border-box;
	border: 0;
	background: none;
	color: inherit;
	font: inherit;
	font-weight: 600;
	text-align: left;
	cursor: pointer;
}

/* Narrow screens: the sidebar becomes a bar on top; the account list folds (tap "Accounts"). */
@media (max-width: 56rem) {
	.app-shell {
		grid-template-columns: minmax(0, 1fr);
	}

	.sidebar {
		position: static;
		height: auto;
		flex-direction: row;
		flex-wrap: wrap;
		align-items: center;
		gap: var(--s-2) var(--s-4);
		padding: var(--s-3) var(--s-4);
	}

	.side-nav {
		display: flex;
		flex-wrap: wrap;
	}

	.side-nav a {
		padding: var(--s-2) var(--s-3);
	}

	.side-accounts {
		flex-basis: 100%;
		padding-top: var(--s-2);
	}

	.side-accounts summary {
		padding-bottom: 0;
		cursor: pointer;
		list-style: revert;
	}

	.side-accounts[open] summary {
		padding-bottom: var(--s-2);
	}

	.side-foot {
		flex-basis: 100%;
		padding-top: var(--s-2);
	}
}

/* Phones: what is desk work (managing accounts, import / export) leaves the bar, and the page gets
   most of the width. Pages lay themselves out for phones with @container (max-width: 36rem). */
@media (max-width: 40rem) {
	.sidebar .desktop-only {
		display: none;
	}

	.sidebar {
		padding: var(--s-2) var(--s-3);
	}

	/* The brand on the left, the year on the right; the pages under them, evenly across the width. */
	.brand {
		flex: 1;
		padding: 0;
	}

	.side-nav {
		flex-basis: 100%;
		display: grid;
		grid-auto-flow: column;
		grid-auto-columns: 1fr;
		gap: var(--s-1);
	}

	.side-nav a {
		padding: var(--s-2) var(--s-1);
		font-size: var(--fs-sm);
		text-align: center;
	}
}

/* Wide screens: the account list stays open (site.js), so its heading is not a toggle. */
@media (min-width: 56.01rem) {
	.side-accounts summary {
		pointer-events: none;
	}
}

@media print {
	.sidebar {
		display: none;
	}

	.app-shell {
		display: block;
	}
}

/* ---- Content column (Views/Shared/_PageLayout.cshtml) ---- */

/* Centre the content on wide screens; each page may narrow itself further. */
.shell-main {
	max-width: 64rem;
	margin: 0 auto;
	padding: var(--s-6) var(--s-5) var(--s-7);
	/* Pages lay out by the width they get (beside the sidebar or not): @container, not @media. */
	container-type: inline-size;
}

.shell-main > * {
	margin-inline: auto;
}

/* Phones: most of the width for the page. */
@media (max-width: 40rem) {
	.shell-main {
		padding: var(--s-4) var(--s-3) var(--s-6);
	}
}

/* Text every page uses: the heading, a quieter line under it, and "nothing here yet". */
.shell-main h1 {
	margin: 0 0 var(--s-3);
	font-size: var(--fs-xl);
}

.shell-main h2 {
	margin: var(--s-6) 0 var(--s-3);
	font-size: var(--fs-lg);
}

.shell-main .lead {
	margin: 0 0 var(--s-5);
	font-size: var(--fs-sm);
	opacity: var(--o-muted);
}

.shell-main .empty {
	opacity: var(--o-muted);
}

/* The working year where a page uses it (headings): a pill, amber when it is not this year. */
.year-tag {
	display: inline-block;
	padding: 0 var(--s-3);
	border-radius: var(--r-sm);
	background: var(--c-primary-bg);
	color: var(--c-primary);
	font-variant-numeric: tabular-nums;
}

.year-tag.other {
	background: var(--c-warn-bg);
	color: var(--c-warn);
}

/* While htmx waits for the server, dim what is being updated a little. */
.htmx-request {
	opacity: var(--o-muted);
	transition: opacity 0.2s;
}

/* ---- The working year (sidebar control, Controllers/YearController.cs) ---- */

.year-pick {
	display: grid;
	grid-template-columns: auto 2rem 1fr 2rem;
	align-items: center;
	gap: var(--s-1);
	padding: var(--s-2) var(--s-3);
	border-radius: var(--r-md);
	background: var(--on-primary-well);
}

.year-label {
	padding-right: var(--s-1);
}

.year-value {
	font-size: var(--fs-xl);
	text-align: center;
	font-variant-numeric: tabular-nums;
}

.year-step {
	width: var(--h-sm);
	height: var(--h-sm);
	border: 0;
	border-radius: var(--r-sm);
	background: var(--on-primary-fill);
	color: inherit;
	font-size: var(--fs-lg);
	line-height: 1;
	cursor: pointer;
}

.year-step:hover {
	background: var(--on-primary-fill-strong);
}

/* Another year than this one: say so loudly, with the way back. */
.year-pick.other {
	background: var(--c-warn);
}

.year-back {
	grid-column: 1 / -1;
	padding: var(--s-1) var(--s-2);
	border: 0;
	border-radius: var(--r-sm);
	background: var(--on-primary-well);
	color: inherit;
	font-size: var(--fs-xs);
	font-weight: 600;
	cursor: pointer;
}

/* Narrow: the picker sits in the top bar, as wide as it needs; the way back gets its own line under
   it (in the first column it would stretch "Year" and push the bar about). Phones drop the why. */
@media (max-width: 56rem) {
	.year-pick {
		grid-template-columns: auto 2rem auto 2rem;
	}
}

@media (max-width: 40rem) {
	.year-back .why {
		display: none;
	}

	.year-back::first-letter {
		text-transform: uppercase;
	}
}
