/* Finanzcockpit – ruhig, gut lesbar, mobil zuerst */
:root {
  --bg: #f4f3ef; --card: #ffffff; --ink: #1c2321; --muted: #6a726f; --line: #e2e0d9;
  --brand: #14322b; --brand-2: #285e50; --accent: #c8a24a;
  --pos: #1f6b4a; --neg: #a23a2a; --warn: #9a6400; --warn-bg: #fdf3dc; --ok-bg: #e5f2ea; --err-bg: #f8e4e0;
  --radius: 10px; --gap: 16px;
  font-synthesis: none;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111614; --card: #1a201e; --ink: #e7ebe9; --muted: #98a19d; --line: #2c3431;
          --brand: #0d2420; --brand-2: #6fb59f; --pos: #6cc69b; --neg: #ef8a78; --warn: #e5b45a;
          --warn-bg: #2e2716; --ok-bg: #16291f; --err-bg: #331c18; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
h3 { font-size: .95rem; margin: 18px 0 8px; color: var(--muted); font-weight: 600; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .86em; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* Kopf */
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 18px;
  padding: 10px max(16px, env(safe-area-inset-left)); background: var(--brand); color: #fff; flex-wrap: wrap; }
.brand { color: #fff; font-weight: 700; letter-spacing: .02em; }
.brand::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 2px;
  background: var(--accent); margin-right: 8px; vertical-align: 1px; }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav a { color: #d6e4df; padding: 6px 10px; border-radius: 6px; white-space: nowrap; }
.nav a.on, .nav a:hover { background: rgba(255,255,255,.12); color: #fff; text-decoration: none; }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent);
  color: #1c1c1c; font-size: .78rem; font-weight: 700; text-align: center; }
.logout { display: flex; gap: 10px; align-items: center; margin: 0; }
.who { color: #b9cdc6; font-size: .86rem; }
button.link { background: none; border: 0; color: #fff; cursor: pointer; padding: 4px; font: inherit; text-decoration: underline; }
@media (max-width: 720px) {
  .top { gap: 8px; } .nav { order: 3; flex-basis: 100%; } .who { display: none; }
}

.wrap { max-width: 1180px; margin: 0 auto; padding: 18px max(16px, env(safe-area-inset-left)) 40px; }
.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 0 0 28px; }
.pagehead { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: var(--gap); }
.card.flush { padding: 0; overflow-x: auto; }
.card.narrow { max-width: 520px; margin: 40px auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); align-items: start; }
.grid2 > .card { margin-bottom: 0; }
.grid2 + .grid2, .grid2 + .card, .kpis + .grid2 { margin-top: var(--gap); }
.grid2 { margin-bottom: var(--gap); }
@media (max-width: 860px) { .grid2 { grid-template-columns: 1fr; } }

/* Kennzahlen */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: var(--gap); }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; color: inherit; }
.card .kpi { background: var(--bg); }
.kpi-label { color: var(--muted); font-size: .82rem; }
.kpi-value { font-size: 1.45rem; font-weight: 700; font-variant-numeric: tabular-nums; margin: 2px 0; letter-spacing: -0.01em; }
.kpi-sub { color: var(--muted); font-size: .8rem; }
a.link-kpi:hover { text-decoration: none; border-color: var(--brand-2); }
.kpi.warn { background: var(--warn-bg); border-color: transparent; }

/* Tabellen */
.t { width: 100%; border-collapse: collapse; }
.t th { text-align: left; font-weight: 600; color: var(--muted); font-size: .8rem; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.t td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.t tr:last-child td { border-bottom: 0; }
.t.small td, .t.small th { padding: 5px 8px; font-size: .86rem; }
.card > .t td:first-child, .card > .t th:first-child { padding-left: 0; }
.card > .t td:last-child, .card > .t th:last-child { padding-right: 0; }
.card.flush .t td:first-child, .card.flush .t th:first-child { padding-left: 16px; }
.card.flush .t td:last-child, .card.flush .t th:last-child { padding-right: 16px; }
.t tr.sum td { font-weight: 700; border-top: 2px solid var(--line); }
.t tr.review { background: var(--warn-bg); }
.t tr.pending { opacity: .75; }
.t tr.off { opacity: .45; }
.r { text-align: right; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--pos); } .neg { color: var(--neg); }
.sub { color: var(--muted); font-size: .82rem; }
.clip { max-width: 520px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted { color: var(--muted); }
.warn { color: var(--warn); } .ok { color: var(--pos); }
.small { font-size: .86rem; }
.note { color: var(--muted); font-size: .85rem; margin: 10px 0 0; }
.note.warn { color: var(--warn); }
ul.note { padding-left: 18px; }
.show-s { display: none; }
@media (max-width: 720px) { .hide-s { display: none; } .show-s { display: block; } .clip { max-width: 56vw; } }

.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .76rem; background: var(--bg); border: 1px solid var(--line); white-space: nowrap; }
.tag.warn { background: var(--warn-bg); border-color: transparent; color: var(--warn); }
.t-income { background: var(--ok-bg); color: var(--pos); border-color: transparent; }
.t-expense, .t-loan_interest { background: var(--err-bg); color: var(--neg); border-color: transparent; }
.t-unknown { background: var(--warn-bg); color: var(--warn); border-color: transparent; }

/* Formulare */
label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); font-size: .92rem; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; min-height: 40px; width: 100%; }
input[type=checkbox] { width: 18px; height: 18px; min-height: 0; accent-color: var(--brand-2); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-2); outline-offset: 1px; border-color: transparent; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > label { flex: 1 1 150px; }
.inline { display: inline-flex; gap: 8px; align-items: center; margin: 0; }
.inline label { flex-direction: row; align-items: center; }
.inline select, .inline input { width: auto; }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; align-items: end; }
.filters .grow { grid-column: span 2; }
.filters .actions { display: flex; gap: 8px; }
@media (max-width: 720px) {
  .t.tx td.act { display: flex; flex-direction: column; gap: 6px; align-items: stretch; }
  .t.tx td.act form, .t.tx td.act .btn { width: 100%; }
}
.filterbox > summary { font-weight: 600; color: var(--ink); }
.filterbox[open] > summary { margin-bottom: 12px; }
@media (min-width: 721px) { .filterbox > summary { display: none; } }
@media (max-width: 720px) {
  .filters { grid-template-columns: 1fr 1fr; }
  .filters .grow, .filters .actions { grid-column: 1 / -1; }
  .filters .actions .btn { flex: 1; }
}
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 0; }
legend { padding: 0 6px; }
fieldset.rule:not(.open) #rulefields { display: none; }
.grants { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: start; margin: 10px 0; }
.grants fieldset { display: flex; flex-direction: column; gap: 6px; }
.grants .btn, .grants .note { grid-column: 1 / -1; justify-self: start; }
@media (max-width: 720px) { .grants { grid-template-columns: 1fr; } }
.t.form input { min-width: 120px; text-align: right; font-variant-numeric: tabular-nums; }
details { margin-top: 10px; }
summary { cursor: pointer; color: var(--brand-2); font-size: .9rem; }
details > form { margin-top: 10px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 14px;
  border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font: inherit;
  font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--brand-2); text-decoration: none; }
.btn.primary { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
.btn.danger { color: var(--neg); }
.btn.small { min-height: 30px; padding: 3px 10px; font-size: .82rem; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; background: var(--ok-bg); }
.flash.error { background: var(--err-bg); color: var(--neg); }
.flash.info { background: var(--warn-bg); color: var(--ink); }

.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 14px; margin: 0; }
.kv dt { color: var(--muted); font-size: .85rem; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 520px) { .kv { grid-template-columns: 1fr; } .kv dd { margin-bottom: 6px; } }

.loans { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.loan, .user { border: 1px solid var(--line); border-radius: 8px; padding: 14px; }
.loan header, .user header { margin-bottom: 10px; display: flex; gap: 8px; flex-wrap: wrap; align-items: baseline; }
.user + .user { margin-top: 12px; }
.loan .kv { grid-template-columns: 96px 1fr; }
.pager { display: flex; justify-content: center; align-items: center; gap: 14px; margin: 12px 0; }

.login { max-width: 380px; margin: 10vh auto 0; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 28px; }
.login h1 { margin-bottom: 4px; }
