:root {
  --bg: #f6f3ee;
  --card: #ffffff;
  --ink: #1d1c1a;
  --muted: #76716a;
  --line: #e7e1d8;
  --soft: #efeae2;
  --accent: #2f5d50;
  --accent-ink: #ffffff;
  --warn: #b5482f;
  --warn-bg: #fbeae4;
  --good: #2f7a4b;
  --good-bg: #e5f3ea;
  --info-bg: #edf0f6;
  --info: #3f5683;
  --c-lebensmittel: #4f8a5b;
  --c-drogerie: #b0618a;
  --c-tanken: #d0912c;
  --c-sonstiges: #5f7aa3;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(40, 30, 10, .04), 0 4px 16px rgba(40, 30, 10, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a;
    --card: #222326;
    --ink: #f1eee9;
    --muted: #a19c94;
    --line: #34353a;
    --soft: #2b2c30;
    --accent: #7fc2ab;
    --accent-ink: #10231d;
    --warn: #f0957d;
    --warn-bg: #3a2420;
    --good: #84d3a0;
    --good-bg: #1f3327;
    --info-bg: #252b38;
    --info: #a9bce4;
    --c-lebensmittel: #73b682;
    --c-drogerie: #d98ab3;
    --c-tanken: #e8b25b;
    --c-sonstiges: #8aa5cf;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
main {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 18px) 16px calc(env(safe-area-inset-bottom) + 110px);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1 { font-size: 1.6rem; margin: 0; letter-spacing: -.02em; }
h2 { font-size: 1rem; margin: 28px 4px 10px; color: var(--muted); font-weight: 600; letter-spacing: .01em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; }

/* Karten */
.card { background: var(--card); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.card + .card { margin-top: 12px; }

/* Kopfzeile mit Monatswechsel */
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 8px; }
.month-switch { display: flex; align-items: center; gap: 4px; }
.month-switch button { width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); font-size: 1.1rem; }
.month-switch button:disabled { opacity: .35; }
.month-label { font-weight: 650; min-width: 128px; text-align: center; }

/* Hero */
.hero-label { color: var(--muted); font-size: .9rem; }
.hero-amount { font-size: 2.5rem; font-weight: 750; letter-spacing: -.03em; margin: 2px 0 10px; }
.bar { height: 10px; border-radius: 99px; background: var(--soft); overflow: hidden; position: relative; }
.bar > span { display: block; height: 100%; border-radius: 99px; background: var(--accent); transition: width .4s ease; }
.bar.over > span { background: var(--warn); }
.bar .tick { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--ink); opacity: .35; border-radius: 2px; }
.hero-meta { display: flex; justify-content: space-between; margin-top: 8px; font-size: .88rem; color: var(--muted); }

/* Hinweise */
.hints { display: grid; gap: 8px; margin-top: 12px; }
.hint { border-radius: 14px; padding: 12px 14px; font-size: .93rem; display: flex; gap: 10px; align-items: flex-start; }
.hint b { flex: none; }
.hint.warn { background: var(--warn-bg); color: var(--warn); }
.hint.good { background: var(--good-bg); color: var(--good); }
.hint.info { background: var(--info-bg); color: var(--info); }
.hint span { color: var(--ink); }

/* Kategorien */
.cat-row { display: grid; grid-template-columns: 34px 1fr auto; gap: 4px 10px; align-items: center; padding: 10px 0; }
.cat-row + .cat-row { border-top: 1px solid var(--line); }
.cat-ico { width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; font-size: 1.05rem; grid-row: span 2; }
.cat-name { font-weight: 600; }
.cat-amount { font-weight: 650; text-align: right; }
.cat-sub { grid-column: 2 / 4; display: flex; align-items: center; gap: 10px; }
.cat-sub .bar { flex: 1; height: 6px; }
.cat-sub .muted { font-size: .8rem; white-space: nowrap; }

.c-lebensmittel { --c: var(--c-lebensmittel); }
.c-drogerie { --c: var(--c-drogerie); }
.c-tanken { --c: var(--c-tanken); }
.c-sonstiges { --c: var(--c-sonstiges); }
.cat-ico { background: color-mix(in srgb, var(--c) 16%, transparent); }
.cat-row .bar > span { background: var(--c); }
.cat-row .bar.over > span { background: var(--warn); }

/* Personen */
.people { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.person { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.person .avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--soft); display: grid; place-items: center; font-weight: 700; font-size: .85rem; margin-bottom: 8px; }
.person .amt { font-size: 1.25rem; font-weight: 700; }
.grand { display: flex; justify-content: space-between; padding: 14px 18px; margin-top: 10px; border-radius: var(--radius); background: var(--soft); font-size: .93rem; }

/* Formular */
.photo-zone { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.photo-btn { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 92px; border-radius: var(--radius); border: 1.5px dashed var(--line); background: var(--card); text-align: center; font-weight: 600; font-size: .92rem; }
.photo-btn.primary { border: none; background: var(--accent); color: var(--accent-ink); }
.photo-btn .big { font-size: 1.6rem; line-height: 1; }
.photo-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.preview { display: flex; gap: 12px; align-items: center; }
.preview img { width: 64px; height: 84px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); cursor: zoom-in; }
.preview .remove { margin-left: auto; border: none; background: none; color: var(--muted); font-size: .88rem; text-decoration: underline; }
.spinner { width: 18px; height: 18px; border: 2.5px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: -4px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

.field { margin-top: 18px; }
.field > label, .field-label { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); margin: 0 4px 6px; }
.input { width: 100%; border: 1.5px solid var(--line); background: var(--card); border-radius: 14px; padding: 13px 14px; font-size: 1rem; outline: none; }
.input:focus { border-color: var(--accent); }
.amount-wrap { position: relative; }
.amount-wrap .input { font-size: 2rem; font-weight: 700; padding: 12px 48px 12px 16px; letter-spacing: -.02em; }
.amount-wrap .cur { position: absolute; right: 18px; top: 50%; transform: translateY(-50%); font-size: 1.5rem; color: var(--muted); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1.5px solid var(--line); background: var(--card); border-radius: 99px; padding: 9px 14px; font-weight: 600; font-size: .93rem; }
.chip[aria-pressed="true"] { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }
.chips.cats .chip { flex: 1 1 calc(50% - 8px); border-radius: 14px; padding: 12px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.btn { display: block; width: 100%; border: none; border-radius: 16px; padding: 15px; font-weight: 700; font-size: 1.05rem; background: var(--accent); color: var(--accent-ink); margin-top: 22px; }
.btn:disabled { opacity: .6; }
.btn.ghost { background: transparent; color: var(--ink); border: 1.5px solid var(--line); font-weight: 600; margin-top: 10px; }
.btn.danger { background: transparent; color: var(--warn); border: 1.5px solid var(--warn-bg); font-weight: 600; margin-top: 10px; }
.error { color: var(--warn); font-size: .9rem; margin-top: 12px; min-height: 1em; }
.scan-ok { margin-top: 10px; font-size: .9rem; color: var(--good); }
.scan-err { margin-top: 10px; font-size: .9rem; color: var(--warn); }

/* Liste */
.filter { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 8px; scrollbar-width: none; }
.filter .chip { white-space: nowrap; padding: 7px 13px; font-size: .88rem; }
.day { margin: 18px 4px 6px; font-size: .82rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.entry { display: grid; grid-template-columns: 38px 1fr auto; gap: 12px; align-items: center; padding: 12px 14px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; width: 100%; text-align: left; }
.entry + .entry { margin-top: 6px; }
.entry .cat-ico { grid-row: auto; width: 38px; height: 38px; }
.entry .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry .meta { font-size: .8rem; color: var(--muted); }
.entry .amt { font-weight: 700; }
.tag { display: inline-block; font-size: .72rem; font-weight: 700; padding: 1px 7px; border-radius: 99px; background: var(--soft); color: var(--muted); margin-right: 4px; }
.tag.personal { background: var(--info-bg); color: var(--info); }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .big { font-size: 2.4rem; margin-bottom: 8px; }
.export { display: block; text-align: center; margin-top: 20px; color: var(--muted); font-size: .9rem; }

/* Verlauf */
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 11px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 12px; font-size: .82rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--c); margin-right: 5px; vertical-align: -1px; }
.trend-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.trend-table th, .trend-table td { padding: 9px 4px; text-align: right; border-bottom: 1px solid var(--line); }
.trend-table th:first-child, .trend-table td:first-child { text-align: left; }
.trend-table th { color: var(--muted); font-weight: 600; font-size: .8rem; }
.up { color: var(--warn); }
.down { color: var(--good); }

/* Einstellungen */
.setting-row { display: grid; grid-template-columns: 1fr 130px; gap: 10px; align-items: center; padding: 6px 0; }
.setting-row .input { padding: 10px 12px; text-align: right; }
.user-line { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--line); }
.user-line:last-child { border-bottom: none; }
details summary { cursor: pointer; font-weight: 600; padding: 4px 0; }

/* Anmeldung */
.auth { min-height: 80vh; display: flex; flex-direction: column; justify-content: center; }
.auth .logo { font-size: 2.6rem; margin-bottom: 6px; }
.auth p { color: var(--muted); margin: 6px 0 20px; }

/* Navigation */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: 1fr 1fr 76px 1fr 1fr; align-items: center;
  max-width: 560px; margin: 0 auto;
  padding: 8px 10px calc(env(safe-area-inset-bottom) + 8px);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.nav-btn { border: none; background: none; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .72rem; color: var(--muted); padding: 4px 0; }
.nav-btn .nav-ico { width: 22px; height: 22px; }
.nav-btn.active { color: var(--accent); font-weight: 700; }
.nav-add { justify-self: center; width: 58px; height: 58px; border-radius: 50%; border: none; background: var(--accent); color: var(--accent-ink); font-size: 2rem; line-height: 1; margin-top: -26px; box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 40%, transparent); }
.nav-add.active { outline: 3px solid color-mix(in srgb, var(--accent) 30%, transparent); }

.toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 92px); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 99px; font-weight: 600; font-size: .92rem; z-index: 40; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); z-index: 50; display: grid; place-items: center; padding: 20px; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }
[hidden] { display: none !important; }

/* Schalter „Von der Haushaltskarte bezahlt“ */
.switch { display: flex; align-items: center; gap: 12px; margin-top: 16px; padding: 12px 14px; background: var(--card);
  border: 1px solid var(--line); border-radius: 14px; cursor: pointer; }
.switch[hidden] { display: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .knob { flex: none; position: relative; width: 46px; height: 28px; border-radius: 14px; background: var(--soft);
  border: 1px solid var(--line); transition: background .15s; }
.switch .knob::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .15s; }
.switch input:checked + .knob { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .knob::after { transform: translateX(18px); }
.switch input:focus-visible + .knob { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch b { display: block; }
.sep-row { display: flex; justify-content: space-between; padding: 6px 0; }
.sep-row.sep-sum { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 10px; }
.tag.separate { background: var(--warn-bg); color: var(--warn); }

/* „Ohne Datum (nur Monat bekannt)“ */
.check { display: flex; align-items: center; gap: 10px; margin: 10px 4px 0; font-size: .95rem; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.field[hidden] { display: none; }

/* Antippbare Karten auf der Übersicht */
button.tap { font: inherit; color: inherit; text-align: left; width: 100%; cursor: pointer; }
button.person.tap { display: block; }
.person .more { color: var(--accent); font-weight: 600; margin-top: 4px; }
button.grand.tap { border: 0; align-items: center; gap: 12px; }
.grand > span > .small { display: block; font-weight: 400; }

/* Papierbuch übernehmen */
.linkish { display: block; margin: 10px 4px 0; padding: 0; border: 0; background: none; color: var(--accent); font: inherit; font-weight: 600; font-size: .92rem; text-align: left; cursor: pointer; }
.imp-row { display: grid; gap: 8px; margin-top: 10px; padding: 12px; }
.imp-row.off { opacity: .45; }
.imp-row.unsure { border-color: var(--warn); }
.imp-top { display: grid; grid-template-columns: 24px 1fr 70px; gap: 8px; align-items: center; }
.imp-top input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); }
.imp-row .input { padding: 10px 12px; }
.imp-sel { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.imp-day { text-align: center; }
.imp-row .check { margin: 0; font-size: .9rem; }
.small-amt .input { font-size: 1.1rem; font-weight: 700; padding: 10px 34px 10px 12px; }
.small-amt .cur { font-size: 1rem; right: 12px; }
.tag.cash { background: var(--good-bg); color: var(--good); }
.search-wrap { margin: 0 0 10px; }
.search-wrap .input { padding: 12px 14px; }
.tag.auto { background: var(--info-bg); color: var(--info); }
.rec-line { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.rec-line .remove { border: none; background: none; color: var(--muted); font-size: .88rem; text-decoration: underline; cursor: pointer; }
.check[hidden] { display: none; }
/* Monatswechsel per Wischen */
@keyframes slideL { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes slideR { from { transform: translateX(-40px); opacity: 0; } to { transform: none; opacity: 1; } }
#entries.slide-left { animation: slideL .22s ease-out; }
#entries.slide-right { animation: slideR .22s ease-out; }
@media (prefers-reduced-motion: reduce) { #entries.slide-left, #entries.slide-right { animation: none; } }
