:root {
	--brand-start: #5b4cf0;
	--brand-end: #9d6bff;
	--positive: #12b886;
	--warning: #f59f00;
	--borrowed: #ff8a4c;
	--credits-start: #0e9f7e;
	--credits-end: #2f9bd6;

	--primary: #5b4cf0;
	--on-primary: #fff;
	--primary-container: #e7e4ff;
	--on-primary-container: #1c1269;
	--bg: #f6f7fb;
	--on-bg: #151827;
	--surface: #fff;
	--surface-variant: #eff0f6;
	--on-surface-variant: #636879;
	--surface-high: #f1f2f8;
	--outline: #d5d7e2;
	--outline-variant: #e6e8f0;
	--error: #e5484d;
	--error-container: #ffe4e4;
	--shadow: 0 6px 24px rgba(21, 24, 39, 0.08);

	color-scheme: light;
	font-family:
		"Inter",
		"Segoe UI",
		Roboto,
		system-ui,
		-apple-system,
		sans-serif;
}

@media (prefers-color-scheme: dark) {
	:root {
		--primary: #b9b0ff;
		--on-primary: #231591;
		--primary-container: #3b2dc2;
		--on-primary-container: #e7e4ff;
		--bg: #0e1016;
		--on-bg: #e6e7ee;
		--surface: #171a23;
		--surface-variant: #232735;
		--on-surface-variant: #a3a7b7;
		--surface-high: #232735;
		--outline: #3a3f50;
		--outline-variant: #2a2e3c;
		--error: #ff6b6f;
		--error-container: #5c1a1d;
		--shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
		color-scheme: dark;
	}
}

* {
	box-sizing: border-box;
}
html,
body {
	margin: 0;
	background: var(--bg);
	color: var(--on-bg);
}
body {
	font-size: 15px;
	line-height: 1.4;
	min-height: 100vh;
}
button,
input,
select {
	font: inherit;
	color: inherit;
}
button {
	cursor: pointer;
	border: 0;
	background: none;
}
:focus-visible {
	outline: 2px solid var(--primary);
	outline-offset: 2px;
}

.muted {
	color: var(--on-surface-variant);
}
.label {
	font-size: 12px;
	font-weight: 500;
	letter-spacing: 0.02em;
}
.bold {
	font-weight: 700;
}
.semi {
	font-weight: 600;
}
.ellipsis {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}
.grow {
	flex: 1;
	min-width: 0;
}
.row {
	display: flex;
	align-items: center;
	gap: 10px;
}
.col {
	display: flex;
	flex-direction: column;
}
.wrap {
	flex-wrap: wrap;
}
.hidden {
	display: none !important;
}

/* ---------- Layout ---------- */

.shell {
	display: grid;
	grid-template-columns: 232px minmax(0, 1fr);
	min-height: 100vh;
}
.sidebar {
	position: sticky;
	top: 0;
	height: 100vh;
	background: var(--surface);
	padding: 24px 16px;
	display: flex;
	flex-direction: column;
	gap: 8px;
	box-shadow: var(--shadow);
}
.logo {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 0 8px 20px;
}
.logo-mark {
	width: 40px;
	height: 40px;
	border-radius: 14px;
	background: linear-gradient(135deg, var(--brand-start), var(--brand-end));
	display: grid;
	place-items: center;
	color: #fff;
}
.nav-item {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 12px 14px;
	border-radius: 16px;
	color: var(--on-surface-variant);
	font-weight: 500;
	text-align: left;
	transition:
		background 0.15s,
		color 0.15s;
}
.nav-item:hover {
	background: var(--surface-high);
}
.nav-item.active {
	background: var(--primary-container);
	color: var(--primary);
	font-weight: 600;
}
.sidebar-foot {
	margin-top: auto;
	display: flex;
	flex-direction: column;
	gap: 10px;
}
.main {
	padding: 24px clamp(16px, 3vw, 40px) 64px;
	max-width: 1180px;
	width: 100%;
	margin: 0 auto;
}
.page {
	display: flex;
	flex-direction: column;
	gap: 16px;
}
.topbar {
	display: flex;
	align-items: center;
	gap: 12px;
	flex-wrap: wrap;
}
.topbar h1 {
	margin: 0;
	font-size: 28px;
	line-height: 1.2;
}
.grid-2 {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 16px;
}

@media (max-width: 860px) {
	.shell {
		grid-template-columns: 1fr;
		padding-bottom: 84px;
	}
	.sidebar {
		position: fixed;
		top: auto;
		bottom: 0;
		left: 0;
		right: 0;
		height: auto;
		flex-direction: row;
		justify-content: space-around;
		padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
		z-index: 20;
	}
	.logo,
	.sidebar-foot {
		display: none;
	}
	.nav-item {
		flex-direction: column;
		gap: 2px;
		padding: 6px 22px;
		font-size: 12px;
	}
	.grid-2 {
		grid-template-columns: 1fr;
	}
}

/* ---------- Components ---------- */

.card {
	background: var(--surface);
	border-radius: 22px;
	padding: 16px;
	box-shadow: var(--shadow);
}
.card h3 {
	margin: 0 0 12px;
	font-size: 15px;
	font-weight: 600;
}
.hero {
	border-radius: 24px;
	padding: 18px;
	color: #fff;
	background: linear-gradient(135deg, var(--brand-start), var(--brand-end));
	box-shadow: 0 10px 28px rgba(91, 76, 240, 0.28);
}
.hero.credits {
	background: linear-gradient(
		135deg,
		var(--credits-start),
		var(--credits-end)
	);
	box-shadow: 0 10px 28px rgba(14, 159, 126, 0.25);
}
.hero .sub {
	color: rgba(255, 255, 255, 0.8);
	font-size: 12px;
	font-weight: 500;
}
.hero .amount {
	font-size: 32px;
	font-weight: 700;
	line-height: 1.2;
}
.hero-stats {
	display: grid;
	grid-template-columns: repeat(3, minmax(0, 1fr));
	gap: 8px;
	margin-top: 12px;
}
.hero-stat {
	background: rgba(255, 255, 255, 0.16);
	border-radius: 14px;
	padding: 8px 10px;
	min-width: 0;
}
.hero-stat .k {
	font-size: 11px;
	color: rgba(255, 255, 255, 0.75);
}
.hero-stat .v {
	font-weight: 600;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}
.badge {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	padding: 4px 10px;
	border-radius: 999px;
	background: rgba(255, 255, 255, 0.2);
	font-size: 12px;
	font-weight: 600;
}
.splitbar {
	display: flex;
	height: 6px;
	border-radius: 999px;
	overflow: hidden;
	background: rgba(255, 255, 255, 0.2);
	margin-top: 12px;
}

.chip {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 7px 14px;
	border-radius: 999px;
	border: 1px solid var(--outline);
	background: transparent;
	font-size: 14px;
	font-weight: 500;
	white-space: nowrap;
	transition:
		background 0.15s,
		border-color 0.15s;
}
.chip:hover {
	background: var(--surface-high);
}
.chip.selected {
	background: var(--primary-container);
	border-color: transparent;
	color: var(--on-primary-container);
}
.chip svg {
	width: 18px;
	height: 18px;
}
.chips {
	display: flex;
	gap: 8px;
	overflow-x: auto;
	scrollbar-width: none;
}
.chips::-webkit-scrollbar {
	display: none;
}

.field {
	display: flex;
	flex-direction: column;
	gap: 4px;
}
.field > span {
	font-size: 12px;
	font-weight: 500;
	color: var(--on-surface-variant);
}
.input {
	width: 100%;
	padding: 12px 16px;
	border-radius: 16px;
	border: 1px solid var(--outline);
	background: var(--surface);
	outline: none;
}
.input:focus {
	border-color: var(--primary);
	box-shadow: 0 0 0 1px var(--primary);
}
.input.pill {
	border-radius: 999px;
}
.input.invalid {
	border-color: var(--error);
}
.error-text {
	color: var(--error);
	font-size: 12px;
}
.search {
	position: relative;
}
.search svg {
	position: absolute;
	left: 14px;
	top: 50%;
	transform: translateY(-50%);
	width: 20px;
	color: var(--on-surface-variant);
}
.search .input {
	padding-left: 44px;
}

.btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	padding: 11px 20px;
	border-radius: 999px;
	font-weight: 600;
	background: var(--primary-container);
	color: var(--on-primary-container);
	transition: filter 0.15s;
}
.btn:hover {
	filter: brightness(0.96);
}
.btn.primary {
	background: linear-gradient(135deg, var(--brand-start), var(--brand-end));
	color: #fff;
	box-shadow: 0 6px 16px rgba(91, 76, 240, 0.3);
}
.btn.text {
	background: none;
	color: var(--primary);
	padding: 8px 12px;
}
.btn.danger {
	color: var(--error);
}
.btn.block {
	width: 100%;
}
.btn:disabled {
	opacity: 0.5;
	cursor: default;
}
.icon-btn {
	width: 40px;
	height: 40px;
	display: grid;
	place-items: center;
	border-radius: 50%;
	color: var(--on-surface-variant);
}
.icon-btn:hover {
	background: var(--surface-high);
}
.icon-btn svg {
	width: 22px;
	height: 22px;
}
.icon-btn.spin svg {
	animation: spin 0.9s linear infinite;
}
@keyframes spin {
	to {
		transform: rotate(360deg);
	}
}

.status-chip {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 6px 12px;
	border-radius: 999px;
	font-size: 13px;
	font-weight: 600;
}
.status-chip svg {
	width: 16px;
	height: 16px;
}

.cat-badge {
	display: grid;
	place-items: center;
	border-radius: 12px;
	flex: none;
}
.cat-badge svg {
	width: 55%;
	height: 55%;
}

.fab {
	position: fixed;
	right: 28px;
	bottom: 28px;
	width: 62px;
	height: 62px;
	border-radius: 50%;
	display: grid;
	place-items: center;
	color: #fff;
	background: linear-gradient(135deg, var(--brand-start), var(--brand-end));
	box-shadow: 0 10px 24px rgba(91, 76, 240, 0.45);
	z-index: 15;
}
.fab svg {
	width: 32px;
	height: 32px;
}
@media (max-width: 860px) {
	.fab {
		right: 20px;
		bottom: 96px;
	}
}

/* ---------- Lists ---------- */

.day-head {
	display: flex;
	align-items: baseline;
	padding: 8px 4px 0;
	font-weight: 600;
}
.item {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 12px;
	background: var(--surface);
	border-radius: 18px;
	box-shadow: var(--shadow);
}
.item .actions {
	display: flex;
	opacity: 0;
	transition: opacity 0.15s;
}
.item:hover .actions,
.item:focus-within .actions {
	opacity: 1;
}
@media (hover: none) {
	.item .actions {
		opacity: 1;
	}
}
.item.dim {
	opacity: 0.6;
}
.list {
	display: flex;
	flex-direction: column;
	gap: 8px;
}
.list.grouped {
	gap: 14px;
	max-height: 420px;
	overflow-y: auto;
	padding-right: 6px;
}

.rank {
	width: 26px;
	height: 26px;
	border-radius: 50%;
	display: grid;
	place-items: center;
	font-size: 12px;
	font-weight: 600;
	background: var(--primary-container);
	color: var(--on-primary-container);
	flex: none;
}
.callout {
	border-radius: 14px;
	padding: 12px;
	background: color-mix(in srgb, var(--positive) 10%, transparent);
	display: flex;
	align-items: center;
	gap: 12px;
	margin-top: 12px;
}

/* Bar chart */
.bars {
	display: flex;
	align-items: flex-end;
	height: 140px;
	gap: 6px;
}
.bars.dense {
	gap: 2px;
}
.bar {
	flex: 1;
	min-height: 2%;
	border-radius: 4px 4px 0 0;
	background: var(--primary);
	transition: height 0.3s;
}
.bar-labels {
	display: flex;
	margin-top: 4px;
	font-size: 10px;
	color: var(--on-surface-variant);
}
.bar-labels span {
	white-space: nowrap;
	overflow: hidden;
}

/* Donut + breakdown */
.breakdown {
	display: flex;
	gap: 20px;
	align-items: flex-start;
}
.donut {
	position: relative;
	width: 120px;
	height: 120px;
	flex: none;
}
.donut svg {
	width: 100%;
	height: 100%;
	transform: rotate(-90deg);
}
.donut .center {
	position: absolute;
	inset: 0;
	display: grid;
	place-content: center;
	text-align: center;
}
.cat-rows {
	display: flex;
	flex-direction: column;
	gap: 10px;
}
.dot {
	width: 8px;
	height: 8px;
	border-radius: 50%;
	flex: none;
}
.track {
	flex: 1;
	height: 4px;
	border-radius: 999px;
	background: var(--surface-variant);
	overflow: hidden;
}
.track > div {
	height: 100%;
}
@media (max-width: 520px) {
	.breakdown {
		flex-direction: column;
		align-items: stretch;
	}
	.donut {
		align-self: center;
	}
}

/* People */
.person {
	background: var(--surface);
	border-radius: 20px;
	box-shadow: var(--shadow);
	overflow: hidden;
}
.person-head {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 14px 16px;
	width: 100%;
	text-align: left;
}
.avatar {
	width: 42px;
	height: 42px;
	border-radius: 50%;
	display: grid;
	place-items: center;
	font-weight: 700;
	color: #fff;
	flex: none;
}
.person-body {
	padding: 0 12px 12px;
	display: flex;
	flex-direction: column;
	gap: 8px;
}
.credit {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 10px 12px;
	border-radius: 14px;
	background: var(--surface-high);
}
.dir-dot {
	width: 4px;
	align-self: stretch;
	border-radius: 4px;
	flex: none;
}

.empty {
	text-align: center;
	padding: 56px 16px;
	color: var(--on-surface-variant);
}

/* ---------- Modal ---------- */

.scrim {
	position: fixed;
	inset: 0;
	background: rgba(10, 12, 20, 0.5);
	display: grid;
	place-items: center;
	padding: 16px;
	z-index: 50;
	animation: fade 0.15s;
}
.modal {
	background: var(--surface);
	border-radius: 28px;
	padding: 24px;
	width: min(480px, 100%);
	max-height: calc(100vh - 32px);
	overflow-y: auto;
	display: flex;
	flex-direction: column;
	gap: 14px;
	animation: rise 0.2s;
}
.modal h2 {
	margin: 0;
	font-size: 21px;
}
.modal-actions {
	display: flex;
	justify-content: flex-end;
	gap: 8px;
	margin-top: 4px;
}
@media (max-width: 560px) {
	.scrim {
		place-items: end center;
		padding: 0;
	}
	.modal {
		border-radius: 28px 28px 0 0;
		max-height: 92vh;
	}
}
@keyframes fade {
	from {
		opacity: 0;
	}
}
@keyframes rise {
	from {
		transform: translateY(16px);
		opacity: 0;
	}
}

.dir-pick {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 10px;
}
.dir-opt {
	text-align: left;
	padding: 12px 14px;
	border-radius: 16px;
	border: 1.5px solid var(--outline);
}
.dir-opt.selected {
	background: color-mix(in srgb, var(--c) 14%, transparent);
	border-color: var(--c);
}

/* Toasts */
#toasts {
	position: fixed;
	left: 50%;
	bottom: 24px;
	transform: translateX(-50%);
	display: flex;
	flex-direction: column;
	gap: 8px;
	z-index: 60;
}
@media (max-width: 860px) {
	#toasts {
		bottom: 100px;
	}
}
.toast {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 12px 16px;
	border-radius: 14px;
	background: #2a2e3c;
	color: #fff;
	box-shadow: var(--shadow);
	animation: rise 0.2s;
}
.toast button {
	color: var(--brand-end);
	font-weight: 600;
}

/* Login */
.login {
	min-height: 100vh;
	display: grid;
	place-items: center;
	padding: 16px;
}
.login .card {
	width: min(400px, 100%);
	padding: 28px;
	display: flex;
	flex-direction: column;
	gap: 14px;
}
