:root {
  --blue: #367da2;
  --blue-dark: #2b6688;
  --bg: #f4f3ef;
  --card: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: #e3e1da;
  --red: #c4372e;
  --green: #2f8a4f;
  --amber: #b7791f;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111214;
    --card: #1c1d20;
    --text: #f2f2f2;
    --muted: #9a9aa0;
    --line: #2e2f33;
    --blue: #5aa3c9;
    --blue-dark: #7ab8d8;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "Helvetica Neue", Helvetica, Arial, sans-serif;
  padding: env(safe-area-inset-top, 0) 16px calc(90px + var(--safe-b));
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
}

[hidden] { display: none !important; }

h1 { font-size: 30px; margin: 0; letter-spacing: -0.02em; }
h2 { font-size: 21px; margin: 0; }
.muted { color: var(--muted); margin: 4px 0 0; }
.hint { color: var(--amber); font-size: 15px; min-height: 1em; margin: 8px 2px; }
.error { color: var(--red); font-size: 15px; min-height: 1.2em; }

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 0 14px;
}

.chip {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 4px 12px;
  font-size: 15px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  border: 1px solid var(--line);
}

textarea, input {
  width: 100%;
  font: inherit;
  font-size: 17px;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  outline: none;
  -webkit-appearance: none;
}
textarea { resize: vertical; min-height: 170px; line-height: 1.45; }
textarea:focus, input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px color-mix(in srgb, var(--blue) 20%, transparent); }
.field { display: block; }

.btn {
  display: block;
  width: 100%;
  text-align: center;
  text-decoration: none;
  font: inherit;
  font-weight: 600;
  color: var(--blue);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-top: 10px;
  cursor: pointer;
}
.btn:active { opacity: 0.7; }
.btn.primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn.primary:disabled { opacity: 0.35; }
.btn.big { padding: 18px; font-size: 19px; margin-top: 14px; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { width: auto; display: inline-block; padding: 8px 14px; font-size: 15px; margin-top: 8px; }
.btn.danger { color: var(--red); }

.icon-btn {
  font-size: 22px;
  background: none;
  border: 0;
  color: var(--muted);
  width: 44px;
  height: 44px;
  cursor: pointer;
}

/* Vorschau */
#preview { margin-top: 10px; }
.pv-to { margin-bottom: 10px; line-height: 1.35; }
.pv-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-top: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.pv-row.total { font-weight: 700; border-top: 2px solid var(--text); }
.pv-meta { color: var(--muted); font-size: 14px; margin-top: 8px; }

.done-card { text-align: center; padding: 28px 16px; margin-top: 6px; }
.check {
  width: 56px; height: 56px; line-height: 56px;
  border-radius: 50%;
  margin: 0 auto 12px;
  background: var(--green);
  color: #fff;
  font-size: 30px;
}

/* Anmeldung */
.login-box { padding-top: 18vh; text-align: center; }
.login-box form { margin-top: 24px; }
.logo {
  width: 72px; height: 72px; line-height: 72px;
  margin: 0 auto 16px;
  border-radius: 18px;
  background: var(--blue);
  color: #fff;
  font-size: 38px;
  font-weight: 700;
}

/* Übersicht */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 10px;
  min-width: 0;
}
.stat span, .stat small { display: block; font-size: 13px; color: var(--muted); }
.stat strong { display: block; font-size: 18px; margin: 2px 0; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat.warn strong { color: var(--amber); }

#search { padding: 11px 14px; }

.group { font-size: 14px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin: 20px 4px 8px; }

.inv {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  text-align: left;
  font: inherit;
  color: inherit;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 6px;
  cursor: pointer;
}
.inv-main, .inv-side { display: flex; flex-direction: column; min-width: 0; }
.inv-main strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inv-side { align-items: flex-end; flex-shrink: 0; }
.inv small { color: var(--muted); font-size: 14px; }
.inv-side strong { font-variant-numeric: tabular-nums; }
.inv.storniert { opacity: 0.5; }
.inv.storniert .inv-side strong { text-decoration: line-through; }

.pill { font-style: normal; font-size: 12px; font-weight: 600; text-transform: capitalize; padding: 1px 8px; border-radius: 99px; margin-top: 3px; }
.pill.offen { background: color-mix(in srgb, var(--amber) 16%, transparent); color: var(--amber); }
.pill.bezahlt { background: color-mix(in srgb, var(--green) 16%, transparent); color: var(--green); }
.pill.storniert { background: color-mix(in srgb, var(--muted) 18%, transparent); color: var(--muted); }

.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* Tab-Leiste */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  justify-content: center;
  gap: 40px;
  padding: 8px 0 calc(8px + var(--safe-b));
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--line);
}
.tabbar button {
  background: none;
  border: 0;
  font: inherit;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 80px;
  cursor: pointer;
}
.tabbar button span { font-size: 22px; line-height: 1.2; }
.tabbar button.active { color: var(--blue); }

/* Bottom-Sheets */
.sheet {
  border: 0;
  padding: 0;
  width: 100%;
  max-width: 560px;
  margin: auto auto 0;
  border-radius: 20px 20px 0 0;
  background: var(--bg);
  color: var(--text);
}
.sheet::backdrop { background: rgba(0, 0, 0, 0.35); }
.sheet-body { padding: 18px 16px calc(20px + var(--safe-b)); }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; }
.label { font-size: 14px; color: var(--muted); display: block; margin: 4px 2px 6px; }
.row { display: flex; gap: 8px; align-items: center; }
.row input { flex: 1; }
.row .btn { margin-top: 0; }

#import-form > label { display: block; margin-bottom: 10px; }
#import-form textarea { min-height: 0; }
#import-form input, #import-form textarea { padding: 10px 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.grid2 > label { min-width: 0; }
.check-row { display: flex; align-items: center; gap: 8px; padding-top: 22px; font-size: 16px; }
.check-row input { width: 22px; height: 22px; padding: 0; accent-color: var(--blue); -webkit-appearance: checkbox; }
label.btn { cursor: pointer; }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + var(--safe-b));
  transform: translate(-50%, 20px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 15px;
  opacity: 0;
  pointer-events: none;
  transition: 0.25s;
  max-width: calc(100% - 32px);
  z-index: 10;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
