/* style.css - how the budget page looks. Made for a phone first. */

/* Colours live here, once. Change a colour here and it changes everywhere. */
:root {
	--bg: #f4f6f4;
	--card: #ffffff;
	--text: #1c2421;
	--muted: #5d6b65;
	--line: #dde3df;
	--accent: #1f7a5a;
	--accent-text: #ffffff;
	--good: #1f7a5a;
	--warn: #b7791f;
	--bad: #c0392b;
	--bar-track: #e4e9e6;
	--field: #ffffff;
}

/* Dark mode follows the phone's own setting. */
@media (prefers-color-scheme: dark) {
	:root {
		--bg: #111614;
		--card: #1b2320;
		--text: #e8efeb;
		--muted: #9bada5;
		--line: #2c3833;
		--accent: #3fb98a;
		--accent-text: #0d1a14;
		--good: #3fb98a;
		--warn: #e0a94a;
		--bad: #ef7b6d;
		--bar-track: #2c3833;
		--field: #141b18;
	}
}

/* Red and black (Indstillinger -> Udseende). Always dark, whatever the phone's own setting says. The
   brand colour (--accent: buttons, links, the lit tab) is red; "good" stays green and "bad" a lighter
   red, so good and bad news still look different. Every colour above must be set here too (a test
   checks it). The page gets data-theme="red" on <html> from app.js (and from a small script in
   index.html, so there is no flash of the other colours). */
:root[data-theme="red"] {
	color-scheme: dark;
	--bg: #0b0b0c;
	--card: #171719;
	--text: #f3f3f4;
	--muted: #a5a5ad;
	--line: #303034;
	--accent: #ff4d4f;
	--accent-text: #0b0b0c;
	--good: #52d19b;
	--warn: #f2a93b;
	--bad: #ff8f8f;
	--bar-track: #2a2a2e;
	--field: #101011;
}

* {
	box-sizing: border-box;
}

/* Without this, the "hidden" attribute loses against our own display rules. */
[hidden] {
	display: none !important;
}

body {
	margin: 0;
	background: var(--bg);
	color: var(--text);
	font: 16px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
	/* Room at the bottom so the tab bar never covers the last card. */
	padding-bottom: calc(76px + env(safe-area-inset-bottom));
}

h2 {
	font-size: 1.05rem;
	margin: 0 0 4px;
}

h3 {
	font-size: 0.9rem;
	font-weight: 600;
	color: var(--muted);
	margin: 18px 0 6px;
}

/* Only the first letter: "onsdag 30. september" becomes "Onsdag 30. september". */
h3::first-letter {
	text-transform: uppercase;
}

.card h3:first-child {
	margin-top: 0;
}

.single-row label {
	margin: 0;
}

ol {
	margin: 6px 0 0;
	padding-left: 22px;
}

li {
	margin-top: 4px;
}

p {
	margin: 0;
}

/* ---- Top bar with the month switcher ---- */

.top {
	position: sticky;
	top: 0;
	z-index: 5;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
	background: var(--card);
	border-bottom: 1px solid var(--line);
}

.month {
	flex: 1;
	text-align: center;
	font-size: 1.15rem;
	font-weight: 600;
	display: flex;
	flex-direction: column;
	align-items: center;
}

.step {
	width: 48px;
	height: 48px;
	border: none;
	border-radius: 12px;
	background: transparent;
	color: var(--accent);
	font-size: 2rem;
	line-height: 1;
	cursor: pointer;
}

.step:active {
	background: var(--bar-track);
}

/* The language button at the right end of the top bar: a small pill with the other language's name. */
.lang-button {
	min-width: 56px;
	height: 36px;
	padding: 0 10px;
	border: 1px solid var(--line);
	border-radius: 18px;
	background: transparent;
	color: var(--accent);
	font: inherit;
	font-size: 0.85rem;
	font-weight: 600;
	cursor: pointer;
}

.lang-button:active {
	background: var(--bar-track);
}

.link {
	border: none;
	background: none;
	color: var(--accent);
	font: inherit;
	font-size: 0.85rem;
	font-weight: 400;
	padding: 2px 8px;
	cursor: pointer;
	text-decoration: underline;
}

/* ---- Page body ---- */

main {
	max-width: 520px;
	margin: 0 auto;
	padding: 12px 16px;
}

.card {
	background: var(--card);
	border: 1px solid var(--line);
	border-radius: 14px;
	padding: 16px;
	margin-bottom: 12px;
}

/* The note at the top of every screen while nobody is logged in: a coloured edge so it is seen. */
.try-banner {
	border-left: 5px solid var(--accent);
}

.try-banner h2 {
	margin-top: 0;
}

.warning {
	max-width: 520px;
	margin: 12px auto 0;
	padding: 10px 14px;
	border-radius: 10px;
	background: var(--warn);
	color: #fff;
}

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

.sync-status {
	margin: 0;
	padding: 4px 16px;
	text-align: center;
	font-size: 0.85rem;
	color: var(--muted);
}

.label {
	color: var(--muted);
	font-size: 0.9rem;
}

/* ---- The big "left to spend" number ---- */

.big-number {
	font-size: 2.4rem;
	font-weight: 700;
	line-height: 1.15;
	margin: 2px 0 6px;
	font-variant-numeric: tabular-nums;
}

.big-number.good {
	color: var(--good);
}

.big-number.bad {
	color: var(--bad);
}

.facts {
	display: flex;
	flex-wrap: wrap;
	gap: 4px 20px;
	margin-top: 10px;
	padding-top: 10px;
	border-top: 1px solid var(--line);
	font-size: 0.95rem;
}

.facts b {
	font-variant-numeric: tabular-nums;
}

/* ---- Forms and buttons ---- */

label {
	display: block;
	margin-top: 10px;
	font-size: 0.9rem;
	color: var(--muted);
}

/* 16px text in fields stops iPhones from zooming in when you tap one. */
input,
select {
	width: 100%;
	min-height: 44px;
	margin-top: 4px;
	padding: 8px 10px;
	border: 1px solid var(--line);
	border-radius: 10px;
	background: var(--field);
	color: var(--text);
	font: inherit;
}

input:focus,
select:focus,
button:focus-visible {
	outline: 2px solid var(--accent);
	outline-offset: 1px;
}

input.bad {
	border-color: var(--bad);
}

button.primary,
label.button {
	display: block;
	width: 100%;
	min-height: 48px;
	margin-top: 14px;
	border: none;
	border-radius: 12px;
	background: var(--accent);
	color: var(--accent-text);
	font: inherit;
	font-weight: 600;
	text-align: center;
	line-height: 48px;
	cursor: pointer;
}

button.secondary,
label.button.secondary {
	display: block;
	width: 100%;
	min-height: 44px;
	margin-top: 10px;
	border: 1px solid var(--accent);
	border-radius: 12px;
	background: transparent;
	color: var(--accent);
	font: inherit;
	font-weight: 600;
	text-align: center;
	line-height: 42px;
	cursor: pointer;
}

label.button {
	color: var(--accent-text);
}

label.button.secondary {
	color: var(--accent);
	margin-top: 10px;
}

.message {
	min-height: 1.4em;
	margin-top: 8px;
	font-size: 0.9rem;
	color: var(--good);
}

.message.bad {
	color: var(--bad);
}

/* ---- Category bars ---- */

.category {
	margin-top: 14px;
}

.category-top {
	display: flex;
	justify-content: space-between;
	gap: 12px;
}

.category-top .amounts {
	color: var(--muted);
	font-size: 0.9rem;
	text-align: right;
	font-variant-numeric: tabular-nums;
}

.bar {
	height: 10px;
	margin-top: 6px;
	border-radius: 5px;
	background: var(--bar-track);
	overflow: hidden;
}

.bar .fill {
	height: 100%;
	border-radius: 5px;
	background: var(--good);
}

.bar .fill.close {
	background: var(--warn);
}

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

.bar .fill.nolimit {
	background: var(--muted);
}

.category .note {
	margin-top: 3px;
	font-size: 0.85rem;
	color: var(--muted);
}

.category .note.over {
	color: var(--bad);
	font-weight: 600;
}

/* ---- The categories card: a fold with a small view when it is folded ---- */

.categories-card summary {
	cursor: pointer;
}

/* The title sits on the same line as the fold arrow. */
.categories-card summary h2 {
	display: inline;
	margin: 0;
}

/* The small view: only there while the card is folded. */
.mini {
	display: none;
	margin-top: 8px;
}

.categories-card details:not([open]) .mini {
	display: block;
}

.mini-row {
	display: grid;
	grid-template-columns: minmax(0, 1fr) 64px auto;
	gap: 10px;
	align-items: center;
	padding: 3px 0;
	font-size: 0.85rem;
	font-weight: 400;
}

.mini-name {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.mini-bar {
	margin-top: 0;
	height: 6px;
}

.mini-bar .fill {
	display: block;
}

.mini-amount {
	color: var(--muted);
	text-align: right;
	font-variant-numeric: tabular-nums;
}

.mini-amount.over {
	color: var(--bad);
	font-weight: 600;
}

/* ---- Spending list ---- */

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

/* A category heading on Udgifter: a clear band with a green edge, and what was spent in it on the right. */
.group-head {
	display: flex;
	justify-content: space-between;
	align-items: baseline;
	gap: 10px;
	margin: 20px 0 2px;
	padding: 8px 10px;
	background: var(--bar-track);
	border-left: 4px solid var(--accent);
	border-radius: 8px;
}

.group-head h3 {
	margin: 0;
	font-size: 1.05rem;
	font-weight: 700;
	color: var(--text);
}

.card .group-head:first-child {
	margin-top: 0;
}

.group-total {
	font-size: 1rem;
	font-weight: 700;
	color: var(--text);
	font-variant-numeric: tabular-nums;
	white-space: nowrap;
}

.list li {
	margin-top: 0;
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 10px 0;
	border-bottom: 1px solid var(--line);
}

.list li:last-child {
	border-bottom: none;
}

.list .what {
	flex: 1;
	min-width: 0;
	overflow-wrap: anywhere;
}

.list .what small {
	display: block;
	color: var(--muted);
}

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

/* The line over the categories: what you have, and how much of it is handed out. */
.category-summary {
	margin: 6px 0 4px;
	font-size: 0.9rem;
	color: var(--muted);
}

.category-summary b {
	color: var(--text);
	font-variant-numeric: tabular-nums;
}

.category-summary b.bad-text {
	color: var(--bad);
}

/* ---- Plan rows ---- */

.row {
	display: grid;
	grid-template-columns: 1fr 112px 44px;
	gap: 8px;
	align-items: center;
	margin-top: 8px;
}

.row input {
	margin-top: 0;
}

.row input[data-field="amount"] {
	text-align: right;
}

/* The optional from / to date box under an income or fixed-bill row. It spans the whole row. */
.dates {
	grid-column: 1 / -1;
	margin: -2px 0 4px;
}

.dates summary {
	color: var(--muted);
	font-size: 0.85rem;
	cursor: pointer;
	padding: 4px 0;
}

.dates-line {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 8px;
}

.dates-line label {
	margin-top: 0;
}

.dates .date-note {
	margin-top: 6px;
}

/* Nothing to say: take no room. */
.date-note:empty {
	display: none;
}

/* Small "tap for more" lines, and the title of a folded card. */
.explain summary {
	color: var(--muted);
	font-size: 0.85rem;
	cursor: pointer;
	padding: 6px 0 0;
}

.fold-title {
	font-size: 1.05rem;
	font-weight: 600;
	cursor: pointer;
	padding: 4px 0;
}

.single-row {
	display: grid;
	grid-template-columns: 1fr 112px;
	gap: 8px;
	align-items: center;
	margin-top: 8px;
}

.single-row input {
	margin-top: 0;
	text-align: right;
}

/* The small line under a number box: when it was typed ("Opdateret 1. okt."). Empty = gone. */
.balance-note {
	margin: 2px 0 0;
	text-align: right;
	font-size: 0.8rem;
	color: var(--muted);
}

.balance-note:empty {
	display: none;
}

.icon {
	width: 44px;
	height: 44px;
	border: none;
	border-radius: 10px;
	background: transparent;
	color: var(--muted);
	font-size: 1.2rem;
	cursor: pointer;
}

.icon:active {
	background: var(--bar-track);
}

.sum-lines {
	margin-top: 8px;
}

.sum-line {
	display: flex;
	justify-content: space-between;
	padding: 3px 0;
	font-variant-numeric: tabular-nums;
}

.sum-line.total {
	margin-top: 4px;
	padding-top: 8px;
	border-top: 1px solid var(--line);
	font-weight: 700;
}

.sum-line.bad {
	color: var(--bad);
}

.sum-line.good {
	color: var(--good);
}

/* ---- Tab bar at the bottom ---- */

.tabs {
	position: fixed;
	left: 0;
	right: 0;
	bottom: 0;
	display: flex;
	background: var(--card);
	border-top: 1px solid var(--line);
	padding-bottom: env(safe-area-inset-bottom);
}

.tabs button {
	flex: 1;
	min-height: 60px;
	border: none;
	background: transparent;
	color: var(--muted);
	font: inherit;
	font-size: 0.95rem;
	cursor: pointer;
}

/* The settings tab is only a gear, so the four word tabs keep their room. */
.tabs button.gear {
	flex: 0 0 64px;
	font-size: 1.5rem;
}

.tabs button.active {
	color: var(--accent);
	font-weight: 700;
	box-shadow: inset 0 3px 0 var(--accent);
}

/* ---- The kid's own page: only the kid's money, no tabs and no month switcher ---- */

.kid-mode .top,
.kid-mode .tabs,
.kid-mode .sync-status {
	display: none !important;
}

.kid-mode body,
body.kid-mode {
	padding-bottom: 24px;
}

.kid-leave {
	text-align: center;
	margin-top: 24px;
}

/* ---- Other people's money (Nathan's savings) ---- */

.pot-buttons {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 8px;
}

.pot .message {
	min-height: 0;
}

.pot .message:empty {
	display: none;
}

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

/* ---- The version number at the bottom ---- */

.app-footer {
	max-width: 520px;
	margin: 0 auto;
	padding: 0 16px 16px;
	text-align: center;
}

.app-footer p {
	margin: 0;
	color: var(--muted);
	font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
	font-size: 0.75rem;
}

/* ---- Tables (the forecast and the reports) ---- */

/* Wide tables scroll sideways inside their box instead of breaking the page. */
.table-scroll {
	overflow-x: auto;
}

table {
	width: 100%;
	border-collapse: collapse;
	font-variant-numeric: tabular-nums;
	font-size: 0.95rem;
}

th,
td {
	padding: 7px 6px;
	text-align: right;
	border-bottom: 1px solid var(--line);
	white-space: nowrap;
}

th:first-child,
td:first-child {
	text-align: left;
}

/* Text columns (a purchase's category and note) sit on the left and may wrap, but never
   shrink to nothing: on a narrow phone the table scrolls sideways instead. */
td.wrap {
	white-space: normal;
	text-align: left;
	overflow-wrap: anywhere;
	min-width: 5.5em;
}

.purchases th:nth-child(2),
.purchases th:nth-child(3) {
	text-align: left;
}

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

tr.total td {
	font-weight: 700;
	border-top: 2px solid var(--line);
}

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

td.good,
.good-text {
	color: var(--good);
}

.report h2 {
	font-size: 1.25rem;
	margin-bottom: 6px;
}

.report h3 {
	margin: 20px 0 4px;
}

.buttons {
	display: flex;
	flex-direction: column;
}

/* ---- Printing: only the report, on white paper ---- */

@media print {
	.top,
	.tabs,
	.sync-status,
	.warning,
	.app-footer,
	.no-print {
		display: none !important;
	}

	body {
		background: #fff;
		color: #000;
		padding: 0;
	}

	main {
		max-width: none;
		padding: 0;
	}

	.card {
		background: #fff;
		border: none;
		padding: 0;
	}

	th,
	td {
		border-bottom: 1px solid #bbb;
		color: #000;
	}

	th {
		color: #444;
	}

	td.bad {
		color: #b00020;
	}

	td.good {
		color: #000;
	}

	.table-scroll {
		overflow: visible;
	}

	/* Keep a table row from being cut in half across two pages. */
	tr {
		break-inside: avoid;
	}

	h3 {
		break-after: avoid;
	}
}

/* ---- Reading a picture of the bank (Overblik -> Læs fra skærmbillede) ---- */

progress {
	width: 100%;
	height: 14px;
	margin-top: 8px;
	accent-color: var(--accent);
}

.scan-picture {
	display: block;
	width: 100%;
	height: auto;
	margin-top: 8px;
	border: 1px solid var(--line);
	border-radius: 10px;
}

/* One line of the bank's list: tick, text, amount - and under it the day and the category. */
.scan-row {
	display: grid;
	grid-template-columns: 28px 1fr 7.5em;
	gap: 4px 8px;
	align-items: center;
	padding: 10px 0;
	border-bottom: 1px solid var(--line);
}

.scan-row.off {
	opacity: 0.6;
}

.scan-row input {
	margin-top: 0;
}

.scan-row input[type="checkbox"] {
	width: 24px;
	height: 24px;
	min-height: 0;
}

.scan-row input[data-scan="amount"] {
	text-align: right;
	font-variant-numeric: tabular-nums;
}

.scan-under {
	grid-column: 2 / 4;
	display: flex;
	align-items: center;
	gap: 8px;
}

.scan-why {
	grid-column: 2 / 4;
	color: var(--warn);
	font-size: 0.85rem;
	font-weight: 600;
}

.scan-date {
	color: var(--muted);
	font-size: 0.85rem;
}

.scan-under select {
	flex: 1;
	min-width: 0;
	margin-top: 0;
}

/* What could not be read: boxed, so it is not missed. */
.scan-unclear {
	margin-top: 14px;
	padding: 10px 12px;
	border: 1px solid var(--warn);
	border-radius: 10px;
}

.scan-unclear h3 {
	margin: 0 0 4px;
}

.scan-lines {
	margin: 6px 0 0;
	padding-left: 18px;
	font-size: 0.9rem;
	overflow-wrap: anywhere;
}

button:disabled {
	opacity: 0.5;
	cursor: default;
}

/* ---- Indstillinger -> Udseende: the choice of colours ---- */

.theme-choices {
	display: grid;
	gap: 8px;
	margin-top: 10px;
}

.theme-choice {
	display: flex;
	align-items: center;
	gap: 12px;
	width: 100%;
	min-height: 56px;
	padding: 8px 12px;
	border: 2px solid var(--line);
	border-radius: 12px;
	background: transparent;
	color: var(--text);
	font: inherit;
	text-align: left;
	cursor: pointer;
}

.theme-choice.on {
	border-color: var(--accent);
}

.theme-swatch {
	flex: 0 0 36px;
	height: 36px;
	border: 3px solid;
	border-radius: 50%;
	display: grid;
	place-items: center;
}

.theme-swatch i {
	width: 14px;
	height: 14px;
	border-radius: 50%;
}

.theme-name {
	display: flex;
	flex-direction: column;
	font-weight: 600;
}

.theme-name small {
	font-weight: 400;
	color: var(--muted);
}
