/* BUDGET v2 – Stylesheet (hell/dunkel automatisch, responsiv, druckfreundlich) */

:root {
	--bg: #f4f6fa;
	--surface: #ffffff;
	--surface-2: #f8fafc;
	--text: #1b2230;
	--muted: #667085;
	--border: #e2e8f0;
	--accent: #2563eb;
	--accent-soft: #e8efff;
	--accent-text: #ffffff;
	--danger: #d92d20;
	--danger-soft: #fdeceb;
	--warn: #d97706;
	--ok: #15803d;
	--ok-soft: #e6f6ec;
	--radius: 12px;
	--shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
	--topbar-h: 56px;
	--sidebar-w: 220px;
}

@media (prefers-color-scheme: dark) {
	:root {
		--bg: #0f141c;
		--surface: #171d28;
		--surface-2: #1c2330;
		--text: #e6eaf2;
		--muted: #93a0b5;
		--border: #2a3342;
		--accent: #6c9bff;
		--accent-soft: #1d2b4a;
		--accent-text: #0b1220;
		--danger: #ff6b5e;
		--danger-soft: #3a1f1d;
		--warn: #f5a524;
		--ok: #4ade80;
		--ok-soft: #12301f;
		--shadow: none;
	}
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
	margin: 0;
	background: var(--bg);
	color: var(--text);
	font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; line-height: 1.2; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
p { margin: 0 0 .75rem; }
b, strong { font-weight: 650; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.strong { font-weight: 600; }
.neg { color: var(--danger); }
.icon { width: 1.1em; height: 1.1em; flex: none; vertical-align: -.2em; }

/* ---- Topbar ------------------------------------------------------------- */

.topbar {
	position: sticky; top: 0; z-index: 20;
	height: var(--topbar-h);
	display: flex; align-items: center; gap: .75rem;
	padding: 0 1rem;
	background: var(--surface);
	border-bottom: 1px solid var(--border);
}

.brand { display: inline-flex; align-items: center; gap: .5rem; font-weight: 750; font-size: 1.15rem; color: var(--text); letter-spacing: .01em; }
.brand:hover { text-decoration: none; }
.brand small { font-weight: 400; color: var(--muted); font-size: .85rem; margin-left: .4rem; }
.logo {
	display: inline-grid; place-items: center;
	width: 30px; height: 30px; border-radius: 8px;
	background: var(--accent); color: var(--accent-text); font-weight: 800;
}
.brand.big { font-size: 1.6rem; margin-bottom: 1.25rem; justify-content: center; }
.brand.big .logo { width: 40px; height: 40px; font-size: 1.3rem; }

.chip {
	display: inline-flex; align-items: center; gap: .4rem;
	padding: .3rem .7rem; border-radius: 999px;
	background: var(--accent-soft); color: var(--accent); font-size: .85rem; font-weight: 600;
	max-width: 40vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chip:hover { text-decoration: none; filter: brightness(.97); }
.spacer { flex: 1; }
.who { display: inline-flex; align-items: center; gap: .35rem; color: var(--muted); font-size: .9rem; }

/* ---- Shell / Sidebar ------------------------------------------------------ */

.shell { display: flex; min-height: calc(100vh - var(--topbar-h)); }

.sidebar {
	width: var(--sidebar-w); flex: none;
	padding: 1rem .75rem;
	background: var(--surface);
	border-right: 1px solid var(--border);
	display: flex; flex-direction: column; gap: .15rem;
}
.sidebar a {
	display: flex; align-items: center; gap: .6rem;
	padding: .55rem .75rem; border-radius: 9px;
	color: var(--text); font-weight: 500;
}
.sidebar a:hover { background: var(--surface-2); text-decoration: none; }
.sidebar a.active { background: var(--accent-soft); color: var(--accent); font-weight: 650; }

main { flex: 1; min-width: 0; padding: 1.5rem clamp(1rem, 3vw, 2rem) 2rem; max-width: 1200px; }

.plain main, main.plainmain { margin: 0 auto; padding-top: 8vh; max-width: 460px; }
.plain .shell { display: block; }

.pagehead { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.1rem; }
.back { display: inline-flex; align-items: center; gap: .3rem; color: var(--muted); font-size: .85rem; margin-bottom: .35rem; }
.toolbar { display: flex; gap: .5rem; flex-wrap: wrap; }

.footer { text-align: center; color: var(--muted); font-size: .8rem; margin-top: 2rem; }

/* ---- Karten, Raster, Kennzahlen ----------------------------------------------- */

.card {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
	padding: 1.1rem 1.25rem;
	margin-bottom: 1rem;
}
.card.narrow { max-width: 440px; margin-inline: auto; }
.card.narrow.left { margin-inline: 0; }
.card.empty { color: var(--muted); text-align: center; padding: 2rem; }
.cardhead { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: .75rem; }
.cardhead h2 { margin: 0; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.kpi { margin: 0; display: flex; flex-direction: column; gap: .15rem; }
.kpi span { color: var(--muted); font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; }
.kpi strong { font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.kpi.bad { border-color: var(--danger); background: var(--danger-soft); }

.grid.projects { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 1rem; }
.project { margin: 0; display: flex; flex-direction: column; gap: .75rem; }
.project header { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.project h2 { margin: 0; font-size: 1.1rem; }
.project h2 a { color: var(--text); }
.project.current { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.project.archived { opacity: .7; }
.project footer { display: flex; justify-content: space-between; align-items: center; gap: .5rem; flex-wrap: wrap; margin-top: auto; }
.row-actions { display: inline-flex; align-items: center; gap: .25rem; }
.stats { display: flex; gap: 1.5rem; margin: 0; }
.stats dt { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
.stats dd { margin: 0; font-weight: 650; font-variant-numeric: tabular-nums; }

/* ---- Tabellen ------------------------------------------------------------------ */

.tablewrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table th, .table td { padding: .55rem .6rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table thead th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; white-space: nowrap; }
.table tbody tr:hover { background: var(--surface-2); }
.table .num { text-align: right; white-space: nowrap; }
.table .indent { padding-left: 1.5rem; }
.table tr.cat th { background: var(--surface-2); font-size: .9rem; text-transform: none; letter-spacing: 0; color: var(--text); font-weight: 650; }
.table tr.over td { background: var(--danger-soft); }
.table tr.locked td { color: var(--muted); }
.table tfoot th, .table tfoot td { font-weight: 700; border-top: 2px solid var(--border); border-bottom: 0; }
.table .usagecol { min-width: 140px; width: 18%; }
.table .rowbtns { white-space: nowrap; text-align: right; }
.table.txn { table-layout: fixed; min-width: 560px; }
.table.txn th:nth-child(1) { width: 110px; }
.table.txn th:nth-child(3) { width: 140px; }
.table.txn th:nth-child(4) { width: 150px; }
.table.txn th:nth-child(5) { width: 100px; }
.table.budget { table-layout: fixed; min-width: 640px; }
.table.budget th:nth-child(1) { width: 64px; }
.table.budget th:nth-child(3), .table.budget th:nth-child(4), .table.budget th:nth-child(5) { width: 140px; }
.table.budget th.usagecol { width: 190px; }

/* ---- Auslastungsbalken ------------------------------------------------------------ */

.usage { display: flex; align-items: center; gap: .5rem; }
.usage .bar { flex: 1; height: 8px; border-radius: 99px; background: var(--border); overflow: hidden; min-width: 60px; }
.usage .bar span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.usage.warn .bar span { background: var(--warn); }
.usage.over .bar span { background: var(--danger); }
.usage small { color: var(--muted); font-size: .78rem; min-width: 3.2em; text-align: right; white-space: nowrap; }
.usage.over small { color: var(--danger); font-weight: 600; }
.kpi .usage { margin-top: .35rem; }

/* ---- Badges, Buttons, Formulare ---------------------------------------------------- */

.badge {
	display: inline-block; padding: .1rem .55rem; border-radius: 99px;
	font-size: .75rem; font-weight: 600;
	background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.badge.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.open { background: var(--ok-soft); color: var(--ok); border-color: transparent; }

.btn {
	display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
	padding: .5rem .9rem; border-radius: 9px;
	border: 1px solid var(--border); background: var(--surface); color: var(--text);
	font: inherit; font-weight: 600; cursor: pointer; line-height: 1.2;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.small { padding: .3rem .65rem; font-size: .85rem; }
.btn.block { width: 100%; }

.iconbtn {
	display: inline-grid; place-items: center;
	width: 32px; height: 32px; padding: 0;
	border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer;
}
.iconbtn:hover { background: var(--accent-soft); color: var(--accent); text-decoration: none; }
.iconbtn.danger:hover { background: var(--danger-soft); color: var(--danger); }
.iconbtn.small { width: 26px; height: 26px; vertical-align: middle; }
form.inline { display: inline; margin: 0; }

.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .9rem; font-size: .85rem; font-weight: 600; color: var(--muted); }
.field.grow { flex: 1 1 220px; }
.field.amount { flex: 0 1 140px; }
input[type="text"], input[type="search"], input[type="password"], select {
	width: 100%; padding: .55rem .7rem; font: inherit; color: var(--text); font-weight: 400;
	background: var(--surface); border: 1px solid var(--border); border-radius: 9px;
}
input:focus, select:focus, .btn:focus-visible, .iconbtn:focus-visible, a:focus-visible {
	outline: 2px solid var(--accent); outline-offset: 1px;
}
.formrow, .filters { display: flex; gap: .75rem; align-items: flex-end; flex-wrap: wrap; }
.formrow .field, .filters .field { margin-bottom: 0; }
.formrow .btn, .filters .btn { margin-bottom: 0; }
.bookform h2 { margin-bottom: .5rem; }
.card.filters { align-items: flex-end; }

.search { display: inline-flex; align-items: center; gap: .4rem; color: var(--muted); padding: 0 .6rem; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); }
.search input { border: 0; background: transparent; padding: .45rem 0; min-width: 160px; }
.search input:focus { outline: none; }
.search:focus-within { outline: 2px solid var(--accent); }

/* ---- Meldungen -------------------------------------------------------------------- */

.flashes { margin-bottom: 1rem; display: grid; gap: .5rem; }
.flash { padding: .65rem .9rem; border-radius: 10px; border: 1px solid transparent; font-weight: 500; }
.flash.error { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.flash.info { background: var(--ok-soft); color: var(--ok); border-color: var(--ok); }

.pagebreak { break-before: page; }

/* ---- Mobil ------------------------------------------------------------------------- */

.navtoggle { display: none; }

@media (max-width: 820px) {
	.navtoggle { display: inline-grid; }
	.sidebar {
		position: fixed; top: var(--topbar-h); bottom: 0; left: 0; z-index: 15;
		transform: translateX(-100%); transition: transform .18s ease;
		box-shadow: 4px 0 16px rgba(0, 0, 0, .15);
	}
	body.nav-open .sidebar { transform: none; }
	.hide-sm, .who { display: none; }
	.chip { max-width: 45vw; }
	.table .usagecol { display: none; }
	.table.budget, .table.txn { min-width: 0; table-layout: auto; }
	.kpi strong { font-size: 1.2rem; }
	.kpis { gap: .6rem; }
}

/* ---- Druck ------------------------------------------------------------------------- */

@media print {
	:root { --bg: #fff; --surface: #fff; --surface-2: #fff; --text: #000; --muted: #444; --border: #bbb; --accent: #000; --danger: #b00; --danger-soft: #fff; --ok-soft: #fff; --ok: #000; }
	body { font-size: 11pt; }
	.topbar, .sidebar, .toolbar, .back, .hide-print, .footer, .flashes, .bookform, .search, .filters { display: none !important; }
	.shell { display: block; }
	main { max-width: none; padding: 0; }
	.card { box-shadow: none; break-inside: avoid; border-color: #999; }
	.usage .bar { border: 1px solid #999; background: #fff; }
	.usage .bar span { background: #666 !important; }
	a { color: inherit; }
	.table tbody tr:hover { background: none; }
}
