:root {
  color-scheme: light;
  --bg: #f5f4f1; --surface: #fcfcfb; --line: #e2e0db; --text: #0b0b0b; --muted: #52514e; --faint: #8a8984;
  --accent: #2a78d6; --accent-soft: #e4eefa; --bar: #2a78d6; --bar-soft: #b9d3f3; --good: #0a7a2f; --bad: #b42318; --warn-bg: #fff6dd;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --line: #2f2e2c; --text: #f0efec; --muted: #c3c2b7; --faint: #8f8e87;
    --accent: #3987e5; --accent-soft: #1d2b3d; --bar: #3987e5; --bar-soft: #2a4466; --good: #4cc274; --bad: #f07a6e; --warn-bg: #3a3218;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --line: #2f2e2c; --text: #f0efec; --muted: #c3c2b7; --faint: #8f8e87;
  --accent: #3987e5; --accent-soft: #1d2b3d; --bar: #3987e5; --bar-soft: #2a4466; --good: #4cc274; --bad: #f07a6e; --warn-bg: #3a3218;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.5rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
.muted { color: var(--muted); } .faint { color: var(--faint); } .small { font-size: 0.85rem; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.between { justify-content: space-between; }
.grid { display: grid; gap: 16px; }
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.tile .label { color: var(--muted); font-size: 0.85rem; }
.tile .value { font-size: 1.45rem; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; }
.tile .sub { color: var(--faint); font-size: 0.8rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--good); } .neg { color: var(--text); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 0.85rem; }
tr.sum td { font-weight: 650; border-top: 2px solid var(--text); border-bottom: none; }
.scroll { overflow-x: auto; }
.btn, button { display: inline-block; border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 8px; padding: 7px 12px; font: inherit; cursor: pointer; }
.btn.primary, button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn:hover, button:hover { text-decoration: none; filter: brightness(0.97); }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; max-width: 100%; }
label { color: var(--muted); font-size: 0.85rem; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--text); font-size: 0.78rem; white-space: nowrap; }
.pill.refund { background: color-mix(in oklab, var(--good) 18%, transparent); }
.note { background: var(--warn-bg); border-radius: 8px; padding: 8px 12px; font-size: 0.88rem; margin-bottom: 16px; }
.ok { background: color-mix(in oklab, var(--good) 15%, transparent); border-radius: 8px; padding: 8px 12px; margin-bottom: 16px; }
.err { background: color-mix(in oklab, var(--bad) 15%, transparent); border-radius: 8px; padding: 8px 12px; margin-bottom: 16px; }
/* Säulen je Monat */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .bar { fill: var(--bar); }
.chart .bar.partial { fill: var(--bar-soft); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + .bar, .chart g:hover .bar { filter: brightness(1.12); }
.chart .axis { stroke: var(--line); }
.chart .grid { stroke: var(--line); stroke-dasharray: 2 3; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .val { fill: var(--text); font-size: 11px; font-weight: 600; }
.tip { position: absolute; pointer-events: none; background: var(--text); color: var(--bg); padding: 6px 9px; border-radius: 6px; font-size: 0.82rem; white-space: nowrap; transform: translate(-50%, -110%); display: none; z-index: 3; }
/* Balken in der Kategorientabelle */
.meter { height: 8px; background: color-mix(in oklab, var(--line) 60%, transparent); border-radius: 0 4px 4px 0; min-width: 60px; }
.meter span { display: block; height: 100%; background: var(--bar); border-radius: 0 4px 4px 0; }
.tx td { font-size: 0.9rem; }
.tx .text { max-width: 420px; }
.tx form.edit { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tx form.edit select { max-width: 190px; }
details.edit summary { cursor: pointer; color: var(--accent); list-style: none; font-size: 0.85rem; }
details.edit summary::-webkit-details-marker { display: none; }
details.edit[open] { background: var(--bg); border-radius: 8px; padding: 8px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; }
.filters > div { display: flex; flex-direction: column; gap: 2px; }
@media (max-width: 700px) {
  .hide-sm { display: none; }
  .tx .text { max-width: none; }
}
@media (max-width: 700px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tile .value { font-size: 1.15rem; }
  .chart { overflow-x: auto; }
  .chart svg { min-width: 420px; }
}

/* -- App-Rahmen: Seitenleiste links, Inhalt rechts --------------------------------------------------------------- */
.app { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--line); position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 18px 12px; }
.side .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.1rem; color: var(--text); padding: 4px 10px 18px; }
.side .brand:hover { text-decoration: none; }
.side .brand img { border-radius: 7px; }
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav a { display: flex; align-items: center; gap: 11px; padding: 9px 10px; border-radius: 8px; color: var(--muted); white-space: nowrap; }
.side nav a:hover { background: var(--bg); color: var(--text); text-decoration: none; }
.side nav a.on { background: var(--accent-soft); color: var(--text); font-weight: 600; }
.side nav a.on .ic { color: var(--accent); }
.side-foot { margin-top: auto; padding: 10px; font-size: 0.78rem; color: var(--faint); }
.ic { width: 19px; height: 19px; flex: none; }
.btn .ic { width: 16px; height: 16px; vertical-align: -3px; margin-right: 2px; }
main { padding: 26px 30px 60px; max-width: 1320px; width: 100%; }

/* -- Übersicht ------------------------------------------------------------------------------------------------- */
.pagehead { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: flex-end; margin-bottom: 18px; }
.kpis { display: grid; gap: 14px; grid-template-columns: 1.35fr 1fr 1fr 1fr; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; min-width: 0; }
.kpi .label { color: var(--muted); font-size: 0.85rem; }
.kpi .value { font-size: 1.6rem; font-weight: 680; font-variant-numeric: tabular-nums; margin: 4px 0 2px; letter-spacing: -0.01em; white-space: nowrap; }
.kpi .sub { color: var(--faint); font-size: 0.8rem; }
.kpi.main { background: var(--accent); border-color: var(--accent); color: #fff; }
.kpi.main .label, .kpi.main .sub { color: rgba(255, 255, 255, 0.85); }
.kpi.main .value { font-size: 2rem; }
.delta { font-weight: 600; }
.cols { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
.cols.wide-left { grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); }
.cols > .card { margin-bottom: 16px; }
.cardhead { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 12px; }
.cardhead h2 { margin: 0; }
.card.flush { padding: 0; }
.cardhead.pad { padding: 16px 16px 4px; }
ul.bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
ul.bars a { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 3px 10px; padding: 6px 8px; margin: 0 -8px; border-radius: 8px; color: var(--text); }
ul.bars a:hover, ul.bars a.on { background: var(--bg); text-decoration: none; }
ul.bars .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
ul.bars .amt { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
ul.bars .amt .faint { font-weight: 400; font-size: 0.82rem; margin-left: 4px; }
ul.bars .meter { grid-column: 1 / -1; height: 7px; min-width: 0; border-radius: 4px; }
ul.bars .meter span { border-radius: 4px; }
table.recent td { padding: 9px 16px; vertical-align: middle; }
table.recent tr:last-child td { border-bottom: none; }
table.recent .d { color: var(--faint); font-variant-numeric: tabular-nums; width: 1%; white-space: nowrap; }
table.recent .m { overflow-wrap: anywhere; }
ul.todo { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
ul.todo li { padding: 10px 12px 10px 34px; border-radius: 8px; background: var(--warn-bg); position: relative; font-size: 0.92rem; }
ul.todo li::before { content: "!"; position: absolute; left: 12px; top: 10px; font-weight: 700; color: var(--muted); }
ul.todo li.done { background: color-mix(in oklab, var(--good) 13%, transparent); }
ul.todo li.done::before { content: "✓"; color: var(--good); }
ul.todo a { color: var(--text); }
.legend-note { margin: 8px 0 0; display: flex; align-items: center; gap: 6px; }
.legend-note .sw { width: 10px; height: 10px; border-radius: 3px; background: var(--bar); display: inline-block; }
.legend-note .sw.soft { background: var(--bar-soft); margin-left: 10px; }
.chart .bar.dim { opacity: 0.35; }
.hero-empty { max-width: 560px; margin: 60px auto; text-align: center; padding: 36px; }

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cols, .cols.wide-left { grid-template-columns: minmax(0, 1fr); gap: 0; }
}
@media (max-width: 760px) {
  .app { display: block; }
  .side { position: sticky; top: 0; z-index: 5; height: auto; flex-direction: row; align-items: center; padding: 0 8px; border-right: none; border-bottom: 1px solid var(--line); overflow-x: auto; }
  .side .brand span, .side-foot { display: none; }
  .side .brand { padding: 8px 6px; }
  .side nav { flex-direction: row; }
  .side nav a { padding: 12px 9px; border-radius: 0; background: none !important; border-bottom: 2px solid transparent; }
  .side nav a.on { border-bottom-color: var(--accent); }
  .side nav a .ic { display: none; }
  main { padding: 16px 16px 50px; }
  .kpi { padding: 12px 14px; }
  .kpi .value { font-size: 1.15rem; }
  .kpi.main { grid-column: 1 / -1; }
  .kpi.main .value { font-size: 1.6rem; }
}
/* Anmeldung */
main.login { max-width: 360px; margin: 12vh auto; padding: 16px; }
main.login form { display: flex; flex-direction: column; gap: 10px; padding: 28px; }
main.login h1 { margin: 0 0 6px; }
main.login img { border-radius: 10px; }
main.login button { margin-top: 4px; padding: 10px; }
main.login input { padding: 10px; }
.side-foot a { color: var(--faint); }
button.linkish { background: none; border: none; padding: 0; color: var(--muted); font-size: 0.85rem; text-decoration: underline; }
.upload { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.upload > div { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.upload input[type=file] { max-width: 100%; }
@media (max-width: 760px) { .side-foot { display: block !important; margin: 0 0 0 auto; padding: 0 8px; white-space: nowrap; } }
.card h2 .ic { width: 18px; height: 18px; vertical-align: -3px; color: var(--accent); margin-right: 4px; }

/* -- Handy: App-Leiste unten, Kopf nur mit Logo ---------------------------------------------------------------- */
.tabbar { display: none; }
@media (max-width: 760px) {
  .side { justify-content: space-between; padding: 0 12px; overflow: visible; }
  .side nav { display: none; }
  .side .brand span { display: inline; }
  .side .brand { padding: 10px 0; font-size: 1rem; }
  .side-foot { display: none !important; }
  main { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
            background: var(--surface); border-top: 1px solid var(--line); padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); }
  .tabbar > a, .tabbar summary { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px; font-size: 0.7rem;
            color: var(--muted); border-radius: 8px; cursor: pointer; list-style: none; min-height: 48px; justify-content: center; }
  .tabbar summary::-webkit-details-marker { display: none; }
  .tabbar .ic { width: 22px; height: 22px; }
  .tabbar > a.on, .tabbar summary.on, .tabbar details[open] summary { color: var(--accent); font-weight: 600; }
  .tabbar > a:hover { text-decoration: none; }
  .tabbar .more { position: relative; }
  .tabbar .sheet { position: absolute; right: 4px; bottom: calc(100% + 10px); background: var(--surface); border: 1px solid var(--line);
            border-radius: 12px; box-shadow: 0 8px 28px rgba(0,0,0,.18); padding: 6px; min-width: 230px; display: grid; gap: 2px; }
  .tabbar .sheet a, .tabbar .sheet button { display: flex; align-items: center; gap: 10px; padding: 12px; border-radius: 8px; color: var(--text);
            font-size: 0.95rem; background: none; border: none; text-align: left; width: 100%; }
  .tabbar .sheet a:hover { background: var(--bg); text-decoration: none; }
  .tabbar .sheet button { color: var(--muted); border-top: 1px solid var(--line); border-radius: 0 0 8px 8px; }

  /* Buchungen als Karten: Datum und Betrag oben, Text, Kategorie darunter */
  .tx-wrap { overflow: visible; }
  table.tx thead { display: none; }
  table.tx, table.tx tbody { display: block; }
  table.tx tr { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "d amt" "text text" "cat cat"; padding: 10px 14px;
            border-bottom: 1px solid var(--line); gap: 2px 10px; }
  table.tx td { border: none; padding: 0; }
  table.tx td.d { grid-area: d; color: var(--faint); font-size: 0.82rem; }
  table.tx td.amt { grid-area: amt; font-weight: 650; }
  table.tx td.text { grid-area: text; }
  table.tx td.cat { grid-area: cat; color: var(--muted); font-size: 0.82rem; }
  .tx form.edit select, .tx form.edit input:not([type=checkbox]) { max-width: none; width: 100%; }
  .tx form.edit button { width: 100%; padding: 10px; }

  /* Diagramm: Schrift in SVG-Einheiten größer, damit sie auf dem Handy lesbar bleibt */
  .chart { overflow: visible; }
  .chart svg { min-width: 0; }
  .chart text { font-size: 19px; }
  .chart .val { font-size: 19px; }
  /* Eingaben und Knöpfe groß genug zum Tippen, 16px verhindert das Zoomen auf dem iPhone */
  input, select, textarea, .btn, button { font-size: 16px; min-height: 40px; }
  input[type=checkbox] { min-height: 0; }
  .filters > div { flex: 1 1 140px; }
  .filters select, .filters input { width: 100%; }
}
.glance { display: grid; gap: 14px; grid-template-columns: repeat(3, minmax(0, 1fr)); margin-bottom: 16px; }
.glance a.kpi { color: var(--text); }
.glance a.kpi:hover { text-decoration: none; border-color: var(--accent); }
h2.section { margin: 8px 0 12px; font-size: 1.05rem; color: var(--muted); }
table.due td { padding-left: 0; }
table.due td.num { padding-right: 0; }
@media (max-width: 760px) {
  .glance { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .glance a.kpi { display: grid; grid-template-columns: 1fr auto; align-items: baseline; gap: 0 10px; }
  .glance .value { grid-row: span 2; font-size: 1.25rem; }
}
