:root {
  --bg: #0b0b0c;
  --surface: #161618;
  --surface2: #202023;
  --line: #2c2c30;
  --text: #f4f4f5;
  --muted: #a6a6ae;
  --red: #de113c;
  --red-text: #ff5c7a;
  --darkred: #7b0822;
  --green: #4ade80;
  --amber: #fbbf24;
  --blue: #60a5fa;
  --radius: 14px;
  --tabbar: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0; min-height: 100dvh; background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none;
}
a { color: var(--red-text); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; color: var(--muted); font-weight: 600; margin-top: .5rem; }
p { margin: .4rem 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.mt { margin-top: 1rem; }
.pre { white-space: pre-line; }
.ic { flex: none; }

/* ---------- Kopf- und Tab-Leiste ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: grid; grid-template-columns: 56px 1fr 56px; align-items: center;
  padding: calc(var(--safe-t) + 6px) 8px 8px; background: rgba(11, 11, 12, .88);
  -webkit-backdrop-filter: saturate(160%) blur(18px); backdrop-filter: saturate(160%) blur(18px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 1.05rem; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-right { display: flex; justify-content: flex-end; }
.iconbtn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; color: var(--text);
  background: transparent; border: 0;
}
.iconbtn:active { background: var(--surface2); }
.iconbtn.flip .ic { transform: scaleX(-1); }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: rgba(16, 16, 18, .94); -webkit-backdrop-filter: saturate(160%) blur(18px); backdrop-filter: saturate(160%) blur(18px);
  border-top: 1px solid var(--line);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); font-size: .68rem; font-weight: 500; }
.tabbar a.on { color: var(--red-text); }
.tabbar a:active { opacity: .6; }

.content { padding: 16px 16px calc(var(--tabbar) + var(--safe-b) + 28px); max-width: 720px; margin: 0 auto; }
body.plain .content { padding-top: calc(var(--safe-t) + 24px); padding-bottom: 40px; }

/* ---------- Bausteine ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack > form { margin: 0; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btnrow { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.btnrow .btn { flex: 1 1 auto; }
section { margin-top: 22px; }
.sec-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.sec-head a { font-size: .9rem; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span { font-size: .8rem; color: var(--muted); font-weight: 500; }
input, select, textarea {
  width: 100%; min-width: 0; font: inherit; font-size: 16px; color: var(--text); background: var(--surface2);
  border: 1px solid var(--line); border-radius: 11px; padding: 11px 12px; min-height: 46px; outline: none;
  -webkit-appearance: none; appearance: none;
}
input[type="date"], input[type="time"] { min-height: 46px; display: block; }
input[type="date"]::-webkit-date-and-time-value, input[type="time"]::-webkit-date-and-time-value { text-align: left; }
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 34px; }
textarea { resize: vertical; line-height: 1.4; }
input:focus, select:focus, textarea:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(222, 17, 60, .25); }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.check input { width: 22px; height: 22px; min-height: 0; padding: 0; accent-color: var(--red); -webkit-appearance: checkbox; appearance: auto; }
.with-btn { display: flex; gap: 8px; align-items: flex-end; }
.with-btn .field { flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 16px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface2); color: var(--text);
  font: inherit; font-weight: 600; font-size: .95rem; cursor: pointer; text-align: center;
  transition: transform .12s ease-out, opacity .12s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.danger { background: transparent; color: var(--red-text); border-color: rgba(255, 92, 122, .35); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn.small { min-height: 46px; padding: 0 14px; }
button[disabled] { opacity: .5; }

.flash { background: var(--surface2); border: 1px solid var(--line); border-left: 3px solid var(--green); border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; font-size: .95rem; }
.flash.err { border-left-color: var(--red); }

.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list.flat { background: transparent; border: 0; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 60px; color: var(--text); border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
a.row:active { background: var(--surface2); }
.row .grow { flex: 1; min-width: 0; }
.row .grow strong, .row .grow small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row small { color: var(--muted); font-size: .82rem; }
.row .end { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: none; }
.row > .ic:last-child { color: var(--muted); }
.avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: var(--surface2); border: 1px solid var(--line); font-weight: 700; color: var(--text); flex: none; }

.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface2); color: var(--muted); border: 1px solid var(--line); }
.badge.green { color: var(--green); border-color: rgba(74, 222, 128, .3); background: rgba(74, 222, 128, .08); }
.badge.amber { color: var(--amber); border-color: rgba(251, 191, 36, .3); background: rgba(251, 191, 36, .08); }
.badge.red { color: #fff; border-color: var(--red); background: var(--red); }

.empty { text-align: center; padding: 28px 16px; color: var(--muted); background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }
.empty .btn { margin-top: 8px; }

.kv { display: grid; gap: 12px; }
.kv.two-col { grid-template-columns: 1fr 1fr; margin: 12px 0; }
.kv span { font-size: .78rem; color: var(--muted); }
.kv p { margin: 2px 0 0; }

/* ---------- Start ---------- */
.hello { font-size: 1.5rem; font-weight: 700; margin: 4px 0 14px; }
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.quick a { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 4px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); color: var(--text); font-size: .8rem; font-weight: 600; }
.quick a .ic { color: var(--red-text); }
.quick a:active { background: var(--surface2); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.stats.four { grid-template-columns: repeat(4, 1fr); }
.stat { display: flex; flex-direction: column; padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); color: var(--text); min-width: 0; }
.stat span { font-size: .78rem; color: var(--muted); }
.stat strong { font-size: 1.3rem; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat small { color: var(--muted); font-size: .8rem; }
.stat.small { padding: 10px; }
.stat.small strong { font-size: .82rem; }
.stat.alert { border-color: rgba(222, 17, 60, .6); }
.stat.alert strong { color: var(--red-text); }
.date-chip { width: 44px; flex: none; text-align: center; background: var(--surface2); border-radius: 10px; padding: 4px 0; }
.date-chip b { display: block; font-size: 1.05rem; }
.date-chip small { font-size: .7rem; }

/* ---------- Auth ---------- */
.auth { max-width: 380px; margin: 0 auto; text-align: center; }
.auth-logo { border-radius: 22px; margin: 12px auto 14px; display: block; }
.auth h1 { font-size: 1.7rem; }
.auth form { text-align: left; margin-top: 20px; }

/* ---------- Suche, Segmente, Chips ---------- */
.search { margin-bottom: 12px; }
.seg { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; margin-bottom: 12px; text-align: center; }
.seg b { font-size: 1.1rem; }
.seg.two-way { grid-template-columns: 1fr 1fr; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg.two-way a { padding: 9px; border-radius: 9px; color: var(--muted); font-weight: 600; }
.seg.two-way a.on { background: var(--surface2); color: var(--text); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips a { flex: none; padding: 7px 13px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); color: var(--muted); font-size: .85rem; font-weight: 500; }
.chips a.on { color: #fff; background: var(--red); border-color: var(--red); }

/* ---------- Kalender ---------- */
.month-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; }
.cal .wd { text-align: center; font-size: .72rem; color: var(--muted); padding: 4px 0; }
.day { aspect-ratio: 1 / 1.05; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding-top: 6px; border-radius: 10px; color: var(--text); font-size: .9rem; }
.day.blank { visibility: hidden; }
.day.today b { background: var(--red); color: #fff; border-radius: 50%; width: 28px; height: 28px; display: grid; place-items: center; margin-top: -3px; }
.day.has { background: var(--surface2); }
.day i { display: flex; gap: 3px; margin-top: 4px; }
.day em, .dot { width: 6px; height: 6px; border-radius: 50%; display: block; background: var(--muted); }
.dot { width: 10px; height: 10px; flex: none; }
.red { --c: var(--red); } .amber { --c: var(--amber); } .blue { --c: var(--blue); } .green { --c: var(--green); } .grey { --c: var(--muted); }
.day em, .dot { background: var(--c, var(--muted)); }
.dayblock { margin-top: 16px; scroll-margin-top: 80px; }
.dayblock h3 { margin-bottom: 6px; }

/* ---------- Dokumente ---------- */
.doc-form .card { margin-bottom: 0; }
.positions { display: flex; flex-direction: column; gap: 10px; }
.pos { background: var(--surface2); border: 1px solid var(--line); border-radius: 12px; padding: 10px; display: grid; gap: 8px; }
.pos.group { border-left: 3px solid var(--red); }
.pos-top { display: flex; align-items: center; gap: 8px; }
.pos-nr { font-weight: 700; color: var(--muted); min-width: 30px; font-size: .9rem; }
.pos-top input { flex: 1; font-weight: 600; }
.pos input, .pos textarea { background: var(--bg); }
.pos-grid { display: grid; grid-template-columns: 1fr 1.3fr 1.3fr; gap: 8px; align-items: end; }
.pos-total { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; padding-bottom: 12px; }
.pos-tools { display: flex; gap: 4px; justify-content: flex-end; }
.pos-tools button { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 1rem; }
.pos-tools button.del { color: var(--red-text); }
.sums { border-top: 1px solid var(--line); padding-top: 10px; display: grid; gap: 6px; font-variant-numeric: tabular-nums; }
.sums div { display: flex; justify-content: space-between; }
.sums span { color: var(--muted); }
.sums .total { font-size: 1.15rem; padding-top: 6px; border-top: 1px solid var(--line); }
.sums .total span { color: var(--text); font-weight: 600; }
.sums.static { margin-top: 12px; }
.sticky-actions { position: sticky; bottom: calc(var(--tabbar) + var(--safe-b) + 8px); display: flex; gap: 8px; padding: 10px; background: rgba(22, 22, 24, .94); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); border: 1px solid var(--line); border-radius: 16px; z-index: 10; }
.sticky-actions .btn { flex: 1; }
.doc-head .dh-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 8px; }
.doc-head small { color: var(--muted); }
.doc-head h2 { font-size: 1.5rem; }
.poslist { display: grid; }
.pl-group { font-weight: 700; padding: 10px 0 6px; border-bottom: 1px solid var(--line); color: var(--red-text); }
.pl-row { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); align-items: flex-start; }
.pl-row small { display: block; color: var(--muted); font-size: .82rem; }
.pl-nr { color: var(--muted); min-width: 28px; font-size: .9rem; }
.pl-row b { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- Belege ---------- */
.upload { display: block; position: relative; }
.upload input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.upload-inner { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 26px 12px; border: 1.5px dashed var(--line); border-radius: var(--radius); background: var(--surface2); text-align: center; }
.upload-inner .ic { color: var(--red-text); }
.upload-inner small { color: var(--muted); }
.upload.chosen .upload-inner { border-color: var(--green); }
.upload-preview { max-height: 220px; max-width: 100%; border-radius: 10px; margin-top: 8px; }
.receipt-img { display: block; margin-bottom: 14px; }
.receipt-img img { width: 100%; border-radius: var(--radius); border: 1px solid var(--line); }

details > summary { cursor: pointer; font-weight: 600; min-height: 44px; display: flex; align-items: center; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary::after { content: '›'; margin-left: auto; color: var(--muted); transition: transform .15s; font-size: 1.3rem; }
details[open] > summary::after { transform: rotate(90deg); }
details.card > form { margin-top: 12px; }

@media (hover: hover) {
  a.row:hover, .quick a:hover { background: var(--surface2); }
  .btn:hover { filter: brightness(1.12); }
}
@media (min-width: 760px) {
  .content { padding-top: 24px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
