/* ------------------------------------------------------------ Farben */
:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --card: #ffffff;
  --card-2: #f0efec;
  --card-3: #e6e5e1;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #7d7c77;
  --line: rgba(0, 0, 0, 0.08);
  --accent: #2a78d6;
  --accent-strong: #1c5cab;
  --accent-ink: #ffffff;
  --accent-soft: rgba(42, 120, 214, 0.12);
  --pos: #006300;
  --neg: #c22f2f;
  --income-mark: #138a5f;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.05);
  --shadow-up: 0 -1px 0 rgba(0, 0, 0, 0.04), 0 8px 32px rgba(0, 0, 0, 0.12);
  --backdrop: rgba(10, 10, 10, 0.38);
  --radius: 20px;
  --radius-sm: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0f0f0e;
    --card: #1a1a19;
    --card-2: #252523;
    --card-3: #31312e;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-3: #8f8e86;
    --line: rgba(255, 255, 255, 0.08);
    --accent: #3987e5;
    --accent-strong: #5598e7;
    --accent-ink: #ffffff;
    --accent-soft: rgba(57, 135, 229, 0.18);
    --pos: #4cc46a;
    --neg: #ef7272;
    --income-mark: #2fc28c;
    --shadow: none;
    --shadow-up: 0 -1px 0 rgba(255, 255, 255, 0.05), 0 8px 32px rgba(0, 0, 0, 0.5);
    --backdrop: rgba(0, 0, 0, 0.6);
  }
}

/* ------------------------------------------------------------ Grundlagen */
*,
*::before,
*::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.muted { color: var(--text-3); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg { display: block; }

.view {
  max-width: 600px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 120px);
  outline: none;
}
@media (min-width: 900px) {
  .view { max-width: 1000px; padding-left: 32px; padding-right: 32px; }
}
.boot { padding: 40vh 0; text-align: center; color: var(--text-3); }

/* ------------------------------------------------------------ Kopfzeile */
.head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 4px 0 16px;
  min-height: 40px;
}
.head h1 { font-size: 28px; line-height: 1.1; letter-spacing: -0.02em; margin: 0; font-weight: 750; }

.period {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 16px;
}
.period-label {
  flex: 1;
  text-align: center;
  font-weight: 650;
  font-size: 17px;
}
.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--card);
  box-shadow: var(--shadow);
  flex: none;
}
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:disabled { opacity: 0.35; }
.icon-btn.flat { background: transparent; box-shadow: none; }

.seg {
  display: inline-flex;
  background: var(--card-2);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}
.seg button {
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-2);
  white-space: nowrap;
}
.seg button[aria-pressed="true"] { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.seg.wide { display: flex; }
.seg.wide button { flex: 1; padding: 8px 6px; }

/* ------------------------------------------------------------ Karten */
.grid { display: grid; gap: 14px; }
@media (min-width: 900px) {
  .grid { grid-template-columns: 1fr 1fr; align-items: start; gap: 18px; }
  .span2 { grid-column: 1 / -1; }
}
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  min-width: 0;
}
.card-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 650;
}
.card-title small { font-weight: 500; color: var(--text-3); font-size: 13px; white-space: nowrap; }

/* Hero */
.hero { padding: 22px 20px 18px; }
.hero-label { color: var(--text-2); font-size: 14px; font-weight: 550; }
.hero-value { font-size: 44px; font-weight: 750; letter-spacing: -0.03em; line-height: 1.1; margin: 4px 0 2px; }
.hero-sub { color: var(--text-3); font-size: 14px; min-height: 20px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px; margin-top: 16px; }
.stat { background: var(--card-2); border-radius: var(--radius-sm); padding: 10px 12px; min-width: 0; }
.stat-label { font-size: 12.5px; color: var(--text-2); font-weight: 550; }
.stat-value { font-size: 17px; font-weight: 700; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-note { font-size: 12px; color: var(--text-3); margin-top: 1px; line-height: 1.3; }

/* Hinweisbanner */
.banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--text);
  font-size: 14.5px;
}
.banner .grow { flex: 1; }
.banner b { display: block; }

/* Kategorienbalken */
.bars { display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px; }
.bar-row {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  grid-template-rows: auto auto;
  column-gap: 10px;
  row-gap: 5px;
  align-items: center;
  text-align: left;
  padding: 8px 6px;
  margin: 0 -6px;
  border-radius: 10px;
  width: calc(100% + 12px);
}
.bar-row:hover { background: var(--card-2); }
.bar-row .emo { grid-row: 1 / span 2; font-size: 20px; text-align: center; }
.bar-row .name { font-size: 15px; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .amt { font-size: 15px; font-weight: 650; text-align: right; }
.bar-row .amt small { display: inline-block; min-width: 38px; color: var(--text-3); font-weight: 500; font-size: 12.5px; margin-left: 6px; }
.bar-track { display: block; grid-column: 2 / span 2; height: 6px; border-radius: 3px; background: var(--card-2); overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 3px; background: var(--accent); min-width: 4px; }

/* Jahresdiagramm */
.chart { position: relative; }
.chart-cols {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 4px;
  height: 150px;
  align-items: end;
  border-bottom: 1px solid var(--line);
}
.chart-col {
  position: relative;
  height: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  border-radius: 6px;
}
.chart-col:hover, .chart-col:focus-visible { background: var(--card-2); }
.chart-bar { width: min(70%, 22px); background: var(--accent); border-radius: 4px 4px 0 0; }
.chart-col.future .chart-bar { opacity: 0.35; }
.chart-inc {
  position: absolute;
  left: 12%;
  right: 12%;
  height: 0;
  border-top: 2.5px solid var(--income-mark);
  border-radius: 2px;
}
.chart-labels { display: grid; grid-template-columns: repeat(12, 1fr); gap: 4px; margin-top: 6px; }
.chart-labels span { text-align: center; font-size: 10.5px; color: var(--text-3); }
.chart-labels span.now { color: var(--text); font-weight: 700; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-2); margin-top: 12px; }
.legend i { display: inline-block; vertical-align: middle; margin-right: 6px; }
.legend .sw-bar { width: 10px; height: 10px; background: var(--accent); border-radius: 2px; }
.legend .sw-line { width: 14px; height: 0; border-top: 2.5px solid var(--income-mark); }
.chart-tip {
  position: absolute;
  top: -6px;
  transform: translate(-50%, -100%);
  background: var(--text);
  color: var(--bg);
  border-radius: 8px;
  padding: 6px 9px;
  font-size: 12px;
  line-height: 1.35;
  pointer-events: none;
  white-space: nowrap;
  z-index: 2;
}

/* Listen */
.list { display: grid; grid-template-columns: minmax(0, 1fr); }
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 6px;
  margin: 0 -6px;
  border-radius: 12px;
  text-align: left;
  width: calc(100% + 12px);
  min-height: 56px;
}
.row:hover { background: var(--card-2); }
.row .emo {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--card-2);
  display: grid;
  place-items: center;
  font-size: 19px;
  flex: none;
}
.row .main { flex: 1; min-width: 0; }
.row .title, .row .sub, .row .amount, .row .amount-sub, .setting .title, .setting .sub { display: block; }
.row .title { font-weight: 600; font-size: 15.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sub { color: var(--text-3); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .right { text-align: right; flex: none; }
.row .amount { font-weight: 650; font-size: 15.5px; white-space: nowrap; }
.row .amount-sub { color: var(--text-3); font-size: 12.5px; white-space: nowrap; }
.row.dim { opacity: 0.55; }
.auto-mark { font-size: 11.5px; color: var(--text-3); margin-left: 4px; }

.day { margin-top: 18px; }
.day:first-child { margin-top: 0; }
.day-head {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 650;
  color: var(--text-2);
  padding: 0 2px 4px;
}

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  box-shadow: var(--shadow);
  border-radius: 14px;
  padding: 0 14px;
  margin-bottom: 12px;
}
.search svg { width: 18px; height: 18px; fill: none; stroke: var(--text-3); stroke-width: 2.2; stroke-linecap: round; flex: none; }
.search input { flex: 1; border: 0; background: none; padding: 13px 0; outline: none; min-width: 0; }
.search input::-webkit-search-cancel-button { filter: grayscale(1); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--card-2);
  font-size: 14px;
  font-weight: 550;
  max-width: 100%;
}
.chip > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip[aria-pressed="true"], .chip.on { background: var(--accent); color: var(--accent-ink); }
.chip.filter { background: var(--accent-soft); margin-bottom: 12px; }
.summary-line { display: flex; justify-content: space-between; color: var(--text-2); font-size: 14px; margin: 0 2px 10px; }

.empty { text-align: center; padding: 28px 12px; color: var(--text-2); }
.empty .big { font-size: 40px; margin-bottom: 6px; }
.empty b { color: var(--text); display: block; font-size: 17px; margin-bottom: 4px; }

details.more > summary { list-style: none; cursor: pointer; color: var(--text-2); font-weight: 600; font-size: 14px; padding: 6px 0; }
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary::before { content: "▸ "; }
details.more[open] > summary::before { content: "▾ "; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 18px;
  border-radius: 14px;
  font-weight: 650;
  background: var(--card-2);
  color: var(--text);
  text-align: center;
  min-height: 48px;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:disabled { opacity: 0.45; }
.btn.danger { color: var(--neg); }
.btn.block { width: 100%; }
.btn.small { padding: 8px 14px; min-height: 36px; font-size: 14px; border-radius: 10px; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }
.link-btn { color: var(--accent); font-weight: 600; font-size: 14.5px; padding: 6px 0; }

/* Einstellungen */
.setting {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
  width: 100%;
  text-align: left;
}
.setting:first-of-type { border-top: 0; }
.setting .main { flex: 1; min-width: 0; }
.setting .title { font-weight: 600; }
.setting .sub { color: var(--text-3); font-size: 13.5px; }
.setting .chev { color: var(--text-3); font-size: 18px; }
.info { color: var(--text-2); font-size: 14px; line-height: 1.5; margin: 0; }
.info + .info { margin-top: 8px; }
.version { text-align: center; color: var(--text-3); font-size: 12.5px; margin-top: 18px; }

/* ------------------------------------------------------------ Tableiste */
.tabbar {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 12px);
  transform: translateX(-50%);
  width: min(560px, calc(100% - 24px));
  display: grid;
  grid-template-columns: 1fr 1fr 72px 1fr 1fr;
  align-items: center;
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: blur(18px) saturate(1.4);
  -webkit-backdrop-filter: blur(18px) saturate(1.4);
  border-radius: 24px;
  box-shadow: var(--shadow-up);
  padding: 6px;
  z-index: 10;
}
.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 0;
  border-radius: 16px;
  color: var(--text-3);
  font-size: 11px;
  font-weight: 600;
}
.tab svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tab svg circle { fill: currentColor; stroke: none; }
.tab[aria-current="page"] { color: var(--accent); }
.fab {
  justify-self: center;
  width: 58px;
  height: 58px;
  border-radius: 20px;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid;
  place-items: center;
  box-shadow: 0 6px 18px rgba(42, 120, 214, 0.4);
  margin-top: -2px;
  transition: transform 0.12s;
}
.fab:active { transform: scale(0.94); }
.fab svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; }

/* ------------------------------------------------------------ Bottom Sheet */
dialog { color: var(--text); }
dialog::backdrop { background: var(--backdrop); }
.sheet {
  border: 0;
  padding: 0;
  margin: auto auto 0;
  width: 100%;
  max-width: 600px;
  max-height: min(94dvh, 900px);
  border-radius: 24px 24px 0 0;
  background: var(--card);
  box-shadow: var(--shadow-up);
  overflow: hidden;
}
.sheet[open] { display: flex; flex-direction: column; animation: up 0.22s cubic-bezier(0.2, 0.9, 0.3, 1); }
@media (min-width: 700px) {
  .sheet { margin: auto; border-radius: 24px; max-height: 90dvh; }
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet[open], .modal[open] { animation: none; } }
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px 4px 20px;
  flex: none;
}
.sheet-head h2 { margin: 0; font-size: 19px; font-weight: 700; }
.sheet-body { padding: 8px 20px 16px; overflow-y: auto; flex: 1; overscroll-behavior: contain; }
.sheet-foot {
  flex: none;
  padding: 12px 20px calc(env(safe-area-inset-bottom) + 14px);
  border-top: 1px solid var(--line);
  background: var(--card);
  display: flex;
  gap: 10px;
}
.sheet-foot .btn.primary { flex: 1; }
.field { margin-top: 16px; }
.field:first-child { margin-top: 4px; }
.field > label, .field-label { display: block; font-size: 13px; font-weight: 650; color: var(--text-2); margin-bottom: 6px; }
.input {
  width: 100%;
  border: 1.5px solid transparent;
  background: var(--card-2);
  border-radius: 14px;
  padding: 13px 14px;
  outline: none;
  min-height: 48px;
}
.input:focus { border-color: var(--accent); background: var(--card); }
.input.invalid { border-color: var(--neg); }
select.input { appearance: none; }
.amount-wrap { position: relative; }
.amount-input {
  font-size: 40px;
  font-weight: 750;
  letter-spacing: -0.02em;
  padding: 10px 52px 10px 16px;
  font-variant-numeric: tabular-nums;
}
.amount-wrap .cur { position: absolute; right: 18px; top: 50%; transform: translateY(-50%); font-size: 28px; font-weight: 700; color: var(--text-3); pointer-events: none; }
.hint { font-size: 13px; color: var(--text-3); margin-top: 6px; }
.hint.err { color: var(--neg); font-weight: 600; }
.info.err { color: var(--neg); font-weight: 600; }
.calc { font-size: 14px; color: var(--text-2); margin-top: 8px; font-weight: 550; }

.cat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
@media (max-width: 360px) { .cat-grid { grid-template-columns: repeat(3, 1fr); } }
.cat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 4px 8px;
  border-radius: 14px;
  background: var(--card-2);
  border: 2px solid transparent;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-2);
  line-height: 1.2;
  min-height: 72px;
  text-align: center;
}
.cat .e { font-size: 24px; line-height: 1; }
.cat span:last-child { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; -webkit-hyphens: auto; hyphens: auto; }
.cat[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.date-row { display: flex; gap: 8px; align-items: center; }
.date-row .input { flex: 1; min-width: 0; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 0; }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; position: absolute; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; background: var(--card-3); border-radius: 999px; transition: background 0.15s; pointer-events: none; }
.switch span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform 0.15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.note-box { background: var(--card-2); border-radius: 12px; padding: 10px 12px; font-size: 13.5px; color: var(--text-2); margin-top: 14px; }

/* ------------------------------------------------------------ Modal */
.modal {
  border: 0;
  border-radius: 22px;
  padding: 22px 20px 18px;
  width: min(420px, calc(100% - 32px));
  background: var(--card);
  box-shadow: var(--shadow-up);
}
.modal[open] { animation: up 0.18s ease-out; }
.modal h3 { margin: 0 0 8px; font-size: 18px; }
.modal p { margin: 0 0 16px; color: var(--text-2); font-size: 15px; line-height: 1.45; white-space: pre-line; }
.modal .btn-col { display: grid; gap: 8px; }

/* ------------------------------------------------------------ Toasts */
.toasts {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 96px);
  width: min(520px, calc(100% - 32px));
  display: grid;
  gap: 8px;
  z-index: 20;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--text);
  color: var(--bg);
  border-radius: 14px;
  padding: 12px 14px 12px 16px;
  font-size: 14.5px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.25);
  pointer-events: auto;
  animation: up 0.2s ease-out;
}
.toast .msg { flex: 1; min-width: 0; }
.toast button { color: var(--accent-strong); font-weight: 700; padding: 4px 6px; white-space: nowrap; }
@media (prefers-color-scheme: dark) { .toast button { color: var(--accent); } }
.toast.error { background: var(--neg); color: #fff; }
.toast.error button { color: #fff; text-decoration: underline; }

.fatal { max-width: 520px; margin: 15vh auto; padding: 24px; }
.fatal h1 { font-size: 22px; }

a { color: var(--accent); }

/* Töpfe */
.pot-parts { display: grid; gap: 1px; margin: -6px 0 8px 52px; }
.pot-parts.in-sheet { margin: 0; background: var(--card-2); border-radius: 12px; padding: 8px 12px; }
.pot-part { display: flex; justify-content: space-between; gap: 12px; font-size: 13.5px; color: var(--text-2); padding: 3px 0; }
.pot-part > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pot-part .num { flex: none; white-space: nowrap; }
.pot-note { color: var(--text-3); font-size: 12.5px; }
.pot-note > span:first-child { white-space: normal; }
.part-row { display: grid; gap: 8px; background: var(--card-2); border-radius: 14px; padding: 10px; margin-bottom: 8px; }
.part-row .input { background: var(--card); min-height: 44px; padding: 10px 12px; }
.part-row .input.invalid { border-color: var(--neg); }
.p-line { display: flex; gap: 8px; align-items: center; }
.p-line .input { flex: 1; min-width: 0; }
.p-line .p-per { flex: 0 0 auto; width: auto; }
.part-del { flex: none; }
