:root {
  --bg: #f3f5f4; --card: #fff; --ink: #1b2422; --muted: #66726f; --line: #e2e7e5;
  --accent: #0f5c55; --accent-2: #e5f1ef; --ok: #2f7d4a; --ok-bg: #e5f3ea;
  --warn: #9a5b00; --warn-bg: #fdf1dc; --bad: #b3261e; --bad-bg: #fbe7e6;
  --radius: 14px; --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  color: var(--ink); background: var(--bg); -webkit-text-size-adjust: 100%;
}
@media (prefers-color-scheme: dark) {
  :root { --bg:#0e1312; --card:#182120; --ink:#e7eeec; --muted:#93a19d; --line:#2a3533;
    --accent:#5cc0b4; --accent-2:#1d3532; --ok:#7ed39a; --ok-bg:#183223; --warn:#f0b75c; --warn-bg:#3a2c12;
    --bad:#ff8a80; --bad-bg:#3d1c1a; }
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; font-size: 16px; line-height: 1.4; }
a { color: var(--accent); text-decoration: none; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 4px 8px; font-weight: 600; }
.num, td.r, .r { font-variant-numeric: tabular-nums; text-align: right; }
.muted { color: var(--muted); } .small { font-size: 13px; }

/* Kopfzeile */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 8px;
  padding: calc(var(--safe-t) + 10px) 16px 10px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px); border-bottom: 1px solid var(--line); }
.topbar h1 { font-size: 20px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back { border: 0; background: none; font-size: 34px; line-height: 1; color: var(--accent); padding: 0 6px 4px 0; cursor: pointer; }
#topActions { display: flex; gap: 6px; }

main { max-width: 860px; margin: 0 auto; padding: 8px 14px calc(96px + var(--safe-b)); }
.loading { padding: 40px; text-align: center; color: var(--muted); }

/* Untere Leiste */
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: flex; justify-content: space-around;
  padding: 6px 4px calc(6px + var(--safe-b)); background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--line); }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); padding: 4px 0; }
.tabbar svg { width: 24px; height: 24px; fill: currentColor; }
.tabbar a.active { color: var(--accent); }
.tabbar .tab-plus svg { background: var(--accent); fill: #fff; border-radius: 50%; padding: 3px; width: 28px; height: 28px; margin-top: -2px; }
@media (prefers-color-scheme: dark) { .tabbar .tab-plus svg { fill: #0e1312; } }

/* Karten & Listen */
.card { background: var(--card); border-radius: var(--radius); padding: 14px 16px; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.card + .card { margin-top: 12px; }
.list { background: var(--card); border-radius: var(--radius); overflow: hidden; }
.list > * { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); color: inherit; }
.list > *:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .sub { font-size: 13px; color: var(--muted); }
.list a::after { content: "›"; color: var(--muted); font-size: 22px; margin-left: 2px; }
.list a.noarrow::after { content: none; }
.empty { padding: 18px 16px; color: var(--muted); text-align: center; font-size: 14px; }

.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 700px) { .kpis { grid-template-columns: repeat(4, 1fr); } }
.kpi { background: var(--card); border-radius: var(--radius); padding: 12px 14px; }
.kpi .l { font-size: 12px; color: var(--muted); }
.kpi .v { font-size: 22px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .s { font-size: 12px; color: var(--muted); }
.kpi.warn .v { color: var(--warn); } .kpi.accent .v { color: var(--accent); }

.bars { display: grid; grid-template-columns: repeat(12, 1fr); gap: 4px; align-items: end; height: 120px; padding-top: 10px; }
.bars div { background: var(--accent); border-radius: 4px 4px 1px 1px; min-height: 2px; position: relative; opacity: .85; }
.bars div.cur { opacity: 1; }
.bar-labels { display: grid; grid-template-columns: repeat(12, 1fr); gap: 4px; font-size: 10px; color: var(--muted); text-align: center; margin-top: 4px; }
.split { display: flex; height: 10px; border-radius: 6px; overflow: hidden; background: var(--line); margin: 8px 0; }
.split .a { background: var(--accent); } .split .b { background: #c9a227; }
.legend { display: flex; gap: 16px; font-size: 13px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

.badge { font-size: 12px; padding: 2px 8px; border-radius: 20px; white-space: nowrap; font-weight: 550; }
.b-offen { background: var(--warn-bg); color: var(--warn); }
.b-bezahlt { background: var(--ok-bg); color: var(--ok); }
.b-storniert { background: var(--bad-bg); color: var(--bad); }
.b-ueberfaellig { background: var(--bad-bg); color: var(--bad); }

/* Formulare */
.form { background: var(--card); border-radius: var(--radius); padding: 4px 16px; }
.field { display: block; padding: 10px 0; border-bottom: 1px solid var(--line); }
.field:last-child { border-bottom: 0; }
.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.field input, .field select, .field textarea { width: 100%; border: 0; background: transparent; color: var(--ink); font: inherit; font-size: 17px; padding: 2px 0; outline: none; }
.field textarea { min-height: 64px; resize: vertical; }
.field .hint { font-size: 12px; margin-top: 3px; }
.hint.ok { color: var(--ok); } .hint.bad { color: var(--bad); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.row3 { display: grid; grid-template-columns: 1fr 2fr; gap: 0 16px; }
.check { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }
.search { width: 100%; padding: 10px 14px; border-radius: 12px; border: 0; background: var(--card); font: inherit; color: var(--ink); margin: 6px 0 10px; }

.seg { display: flex; background: var(--line); border-radius: 10px; padding: 2px; margin: 8px 0; }
.seg button { flex: 1; border: 0; background: transparent; padding: 9px; border-radius: 8px; font: inherit; font-weight: 550; color: var(--ink); cursor: pointer; }
.seg button.on { background: var(--card); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; border-radius: 12px; padding: 12px 18px;
  font: inherit; font-weight: 600; background: var(--accent); color: #fff; cursor: pointer; text-align: center; }
@media (prefers-color-scheme: dark) { .btn { color: #0e1312; } }
.btn.sec { background: var(--accent-2); color: var(--accent); }
.btn.ghost { background: transparent; color: var(--accent); padding: 8px 10px; }
.btn.danger { background: var(--bad-bg); color: var(--bad); }
.btn.sm { padding: 6px 12px; font-size: 14px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.actions { display: grid; gap: 10px; margin: 16px 0; }
.actions.two { grid-template-columns: 1fr 1fr; }

/* Leistungszeilen */
.line { display: grid; grid-template-columns: 24px 1fr auto; gap: 10px; align-items: center; }
.line > div { min-width: 0; }
.line .title { white-space: normal; }
.line input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); }
.newline { background: var(--card); border-radius: var(--radius); padding: 4px 16px; margin-top: 10px; position: relative; }
.newline .rm { position: absolute; right: 8px; top: 6px; }
.total { display: flex; justify-content: space-between; font-size: 20px; font-weight: 700; padding: 14px 4px; }

/* Dialog & Toast */
dialog { border: 0; border-radius: 18px; padding: 0; width: min(520px, 94vw); background: var(--bg); color: var(--ink); }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog form { padding: 16px; }
dialog h3 { margin: 4px 4px 12px; }
#toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%) translateY(20px); opacity: 0;
  background: #1b2422; color: #fff; padding: 10px 18px; border-radius: 24px; font-size: 14px; transition: .25s; pointer-events: none; z-index: 50; max-width: 90vw; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { background: var(--bad); }

/* Login */
.login { max-width: 360px; margin: 12vh auto 0; text-align: center; }
.login .logo { width: 72px; height: 72px; border-radius: 18px; margin-bottom: 10px; }
.login .form { text-align: left; margin: 18px 0 12px; }

/* ===== Rechnung ===== */
.paper { background: #fff; color: #111; padding: 28px 26px; border-radius: 6px; box-shadow: 0 2px 10px rgba(0,0,0,.08);
  font-size: 13px; line-height: 1.45; position: relative; overflow: hidden; }
.paper .ph { display: flex; justify-content: space-between; gap: 20px; border-bottom: 2px solid #0f5c55; padding-bottom: 12px; }
.paper .pname { font-size: 19px; font-weight: 700; color: #0f5c55; }
.paper .ptitle { color: #555; }
.paper .pcontact { text-align: right; font-size: 12px; color: #444; }
.paper .addr { margin: 26px 0 18px; display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.paper .sender { font-size: 9.5px; color: #777; text-decoration: underline; margin-bottom: 4px; }
.paper .meta td { padding: 1px 0 1px 14px; } .paper .meta td:first-child { color: #555; padding-left: 0; }
.paper h3 { font-size: 18px; margin: 4px 0 10px; }
.paper .ins { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; background: #f3f7f6; border-radius: 6px; padding: 10px 12px; margin-bottom: 14px; }
.paper .ins b { display: block; font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: #0f5c55; margin-bottom: 2px; }
.paper table.items { width: 100%; border-collapse: collapse; margin: 10px 0; }
.paper .items th { text-align: left; font-size: 11px; color: #555; border-bottom: 1px solid #bbb; padding: 6px 4px; font-weight: 600; }
.paper .items td { padding: 6px 4px; border-bottom: 1px solid #eee; vertical-align: top; }
.paper .items .r, .paper .items th.r { text-align: right; white-space: nowrap; }
.paper .items tfoot td { border: 0; font-weight: 700; font-size: 15px; padding-top: 10px; border-top: 2px solid #111; }
.paper .note { margin: 12px 0; }
.paper .bank { background: #f3f7f6; padding: 10px 12px; border-radius: 6px; margin: 12px 0; }
.paper .sign { margin-top: 44px; display: flex; justify-content: space-between; gap: 30px; }
.paper .sign div { border-top: 1px solid #888; padding-top: 4px; font-size: 11px; color: #666; width: 45%; }
.paper .foot { margin-top: 26px; padding-top: 8px; border-top: 1px solid #ddd; font-size: 10.5px; color: #666; text-align: center; }
.paper .stamp { position: absolute; top: 38%; left: 50%; transform: translate(-50%,-50%) rotate(-18deg); font-size: 72px; font-weight: 800;
  color: rgba(179,38,30,.16); border: 6px solid rgba(179,38,30,.16); padding: 0 24px; border-radius: 12px; pointer-events: none; }
@media (max-width: 520px) { .paper { padding: 18px 14px; font-size: 12px; } .paper .ph { flex-direction: column; } .paper .pcontact { text-align: left; } .paper .ins { grid-template-columns: 1fr; } }

@media print {
  @page { size: A4; margin: 14mm 16mm; }
  body { background: #fff; }
  .topbar, .tabbar, .noprint, #toast { display: none !important; }
  main { padding: 0; max-width: none; }
  .paper { box-shadow: none; padding: 0; border-radius: 0; font-size: 11pt; }
  .paper .ph { flex-direction: row !important; } .paper .pcontact { text-align: right !important; }
  .paper .ins { grid-template-columns: 1fr 1fr !important; }
}
