/* Haushaltsbuch – Gestaltung angelehnt an Kontoauszug und Haushaltsbuch aus Papier.
   Kuli-Blau für alles, was man anfassen kann. Rotstift für Warnungen.
   Bleistift (grau, gestrichelt) = automatisch vorgeschlagen, Kuli (fest) = bestätigt. */

@font-face { font-family: "Heros"; src: url("/fonts/heros-regular.woff") format("woff"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Heros"; src: url("/fonts/heros-bold.woff") format("woff"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Heros Cn"; src: url("/fonts/heros-cn-regular.woff") format("woff"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Heros Cn"; src: url("/fonts/heros-cn-bold.woff") format("woff"); font-weight: 700; font-display: swap; }

:root {
  --paper: #EEF1F0;
  --sheet: #FFFFFF;
  --band: #F2F6F3;
  --rule: #D5DCD8;
  --ink: #1C2433;
  --ink-2: #4B5566;
  --pencil: #8A93A0;
  --pen: #2846C4;
  --pen-soft: #E3E8FA;
  --pen-text: #FFFFFF;
  --red: #C23A22;
  --red-soft: #F8E6E2;
  --green: #1E7548;
  --green-soft: #E2F0E7;
  --bar: #2846C4;
  --bar-future: #DCE1E6;
  --radius: 6px;
  --nav-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --sans: "Heros", "Helvetica Neue", Helvetica, Roboto, Arial, sans-serif;
  --cond: "Heros Cn", "Roboto Condensed", "Arial Narrow", "Helvetica Neue", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #151A24; --sheet: #1D2431; --band: #212938; --rule: #2F3849; --ink: #E3E7EE; --ink-2: #A9B1BF;
    --pencil: #6F7889; --pen: #8FA4FF; --pen-soft: #26305A; --pen-text: #10162A; --red: #FF7F6A; --red-soft: #3B2324;
    --green: #63C690; --green-soft: #1C3528; --bar: #8FA4FF; --bar-future: #2C3546;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #151A24; --sheet: #1D2431; --band: #212938; --rule: #2F3849; --ink: #E3E7EE; --ink-2: #A9B1BF;
  --pencil: #6F7889; --pen: #8FA4FF; --pen-soft: #26305A; --pen-text: #10162A; --red: #FF7F6A; --red-soft: #3B2324;
  --green: #63C690; --green-soft: #1C3528; --bar: #8FA4FF; --bar-future: #2C3546;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 400 16px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--pen); }
:focus-visible { outline: 2px solid var(--pen); outline-offset: 2px; }
.num, .amt { font-family: var(--cond); font-variant-numeric: tabular-nums lining-nums; }
.muted { color: var(--ink-2); }
.faint { color: var(--pencil); }
.small { font-size: 14px; }
.income { color: var(--green); }
.hidden { display: none !important; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Gerüst ---------- */
.shell { min-height: 100vh; padding-bottom: calc(var(--nav-h) + var(--safe-b) + 28px); }
.topbar { padding: calc(env(safe-area-inset-top, 0px) + 18px) 18px 4px; }
.topbar-inner, .page { max-width: 720px; margin: 0 auto; }
.topbar-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.topbar h1 { font: 700 15px/1.2 var(--sans); margin: 0; color: var(--ink-2); letter-spacing: .01em; }
.page { padding: 0 18px 24px; }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: var(--sheet); border-top: 1px solid var(--rule);
  display: flex; justify-content: center;
}
.nav-inner { display: flex; width: 100%; max-width: 560px; }
.nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--ink-2); text-decoration: none; font-size: 12px; position: relative;
}
.nav a svg { width: 22px; height: 22px; }
.nav .pill { display: flex; }
.nav a.active { color: var(--pen); font-weight: 700; }
.nav a.active::before {
  content: ""; position: absolute; top: 0; left: 28%; right: 28%; height: 3px; background: var(--pen); border-radius: 0 0 2px 2px;
}
@media (min-width: 900px) {
  .nav { top: 0; bottom: 0; right: auto; width: 104px; height: auto; border-top: 0; border-right: 1px solid var(--rule); padding: 28px 0; }
  .nav-inner { flex-direction: column; justify-content: flex-start; gap: 4px; }
  .nav a { flex: 0 0 68px; }
  .nav a.active::before { top: 14px; bottom: 14px; left: 0; right: auto; width: 3px; height: auto; border-radius: 0 2px 2px 0; }
  .shell { padding-left: 104px; padding-bottom: 40px; }
}

/* ---------- Blätter & Überschriften ---------- */
.card { background: var(--sheet); border-radius: var(--radius); padding: 16px; margin-bottom: 18px; border: 1px solid var(--rule); }
.card h2, .section-title { font: 700 19px/1.2 var(--cond); margin: 0 0 12px; }
.section-title { display: flex; justify-content: space-between; align-items: baseline; margin: 28px 0 10px; }
.section-title .muted { font: 400 14px var(--sans); }
.card-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; gap: 12px; }
.card-head h2 { margin: 0; }

/* ---------- Bedienelemente ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none;
  border: 1.5px solid var(--rule); border-radius: 8px; padding: 10px 16px; font-weight: 700; cursor: pointer;
  background: var(--sheet); color: var(--ink); min-height: 46px;
}
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--pen); border-color: var(--pen); color: var(--pen-text); }
.btn.danger { color: var(--red); border-color: color-mix(in srgb, var(--red) 40%, var(--rule)); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--pen); padding: 6px 4px; min-height: 36px; }
.btn.block { width: 100%; }
.btn.sm { padding: 6px 12px; min-height: 36px; font-size: 14px; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 8px; border: 1.5px solid var(--rule); background: var(--sheet);
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; color: var(--ink);
}
.icon-btn svg { width: 20px; height: 20px; }

.seg { display: inline-flex; gap: 22px; }
.seg button {
  border: 0; background: none; padding: 6px 0; cursor: pointer; color: var(--ink-2);
  font: 400 16px var(--sans); border-bottom: 2px solid transparent;
}
.seg button.on { color: var(--ink); font-weight: 700; border-bottom-color: var(--ink); }

.period { display: flex; align-items: center; gap: 10px; margin: 6px 0 18px; }
.period-label { flex: 1; font: 700 34px/1.05 var(--cond); letter-spacing: -.01em; }
.period-label small { display: block; font: 400 14px/1.4 var(--sans); color: var(--ink-2); margin-top: 4px; letter-spacing: 0; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 14px; color: var(--ink-2); margin-bottom: 5px; }
.input, select.input, textarea.input {
  width: 100%; border: 1.5px solid var(--rule); background: var(--sheet); border-radius: 8px;
  padding: 10px 12px; min-height: 48px; outline: none; appearance: none; -webkit-appearance: none;
}
select.input {
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-2) 50%), linear-gradient(135deg, var(--ink-2) 50%, transparent 50%);
  background-position: calc(100% - 18px) 52%, calc(100% - 13px) 52%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 34px;
}
.input:focus { border-color: var(--pen); }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }

/* ---------- Abrechnung (das Herzstück) ---------- */
.statement { background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--radius); padding: 18px 18px 16px; margin-bottom: 18px; }
.stmt-row { display: flex; justify-content: space-between; align-items: baseline; padding: 5px 0; }
.stmt-row .lbl { color: var(--ink-2); }
.stmt-row .amt { font-size: 22px; }
.stmt-row.out .amt { font-size: 22px; }
.stmt-total { margin-top: 8px; padding-top: 10px; border-top: 1.5px solid var(--ink); }
.stmt-total .lbl { color: var(--ink); font-weight: 700; }
.stmt-total .amt { font: 700 40px/1 var(--cond); padding-bottom: 5px; border-bottom: 4px double currentColor; }
.stmt-total .amt.neg { color: var(--red); }
.stmt-note { margin-top: 12px; font-size: 14px; color: var(--ink-2); }
.stmt-note b { color: var(--ink); font-family: var(--cond); font-size: 16px; }
.delta { font: 700 15px var(--cond); white-space: nowrap; }
.delta.good { color: var(--green); }
.delta.bad { color: var(--red); }
.delta.flat { color: var(--pencil); font-weight: 400; }

/* ---------- Diagramm ---------- */
.chart { width: 100%; height: 150px; display: block; }
.chart .bar { fill: var(--bar); }
.chart .bar.dim { fill: var(--bar-future); }
.chart .grid { stroke: var(--ink); stroke-width: 1.5; }
.chart .avg { stroke: var(--red); stroke-dasharray: 6 5; stroke-width: 1.5; }
.chart-labels { position: relative; height: 20px; font: 400 13px var(--cond); color: var(--ink-2); }
.chart-labels span { position: absolute; transform: translateX(-50%); top: 3px; }
#chart-cap { margin-top: 6px; }

/* ---------- Kategorien ---------- */
.catlist { list-style: none; margin: 0 -16px; padding: 0; }
.catlist li { display: flex; gap: 12px; padding: 11px 16px 12px; cursor: pointer; }
.catlist li:nth-child(even) { background: var(--band); }
.tab { width: 5px; align-self: stretch; border-radius: 2px; flex: 0 0 5px; }
.cat-main { flex: 1; min-width: 0; }
.cat-top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.cat-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cat-amt { font: 700 19px var(--cond); white-space: nowrap; }
.cat-sub { display: flex; justify-content: space-between; font-size: 14px; color: var(--ink-2); margin-top: 1px; gap: 8px; }
.meter { height: 4px; background: var(--rule); border-radius: 2px; overflow: hidden; margin-top: 8px; }
.meter > i { display: block; height: 100%; }
.meter.over > i { background: var(--red) !important; }

/* ---------- Buchungen (Kontoauszug) ---------- */
.day-head { font: 700 15px var(--cond); color: var(--ink-2); margin: 20px 0 6px; display: flex; justify-content: space-between; }
.txlist { background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--radius); overflow: hidden; }
.tx { display: flex; align-items: center; gap: 12px; padding: 11px 14px; cursor: pointer; }
.tx:nth-child(even) { background: var(--band); }
.group .tx:nth-child(even) { background: none; }
.group .tx:nth-child(odd) { background: var(--band); }
.txlist .day-head { margin: 0; padding: 14px 14px 6px; border-top: 1.5px solid var(--ink); }
.txlist .group:first-child .day-head { border-top: 0; }
.tx:active { background: var(--pen-soft); }
.tx .tab { align-self: stretch; }
.tx-date { font: 400 14px var(--cond); color: var(--ink-2); flex: 0 0 42px; }
.tx-main { flex: 1; min-width: 0; }
.tx-title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-desc { font-size: 14px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-right { text-align: right; flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-end; }
.tx-amt { font: 700 18px var(--cond); }
.chip {
  font: 400 13px/1.2 var(--sans); padding: 2px 7px; margin-top: 4px; border-radius: 4px; cursor: pointer;
  background: transparent; color: var(--ink); border: 1.5px solid var(--ink);
  max-width: 160px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chip.auto { color: var(--ink-2); border: 1.5px dashed var(--pencil); }
.chip.none { color: var(--red); border: 1.5px dashed var(--red); }

.toolbar { display: flex; gap: 8px; margin: 8px 0 0; flex-wrap: wrap; }
.toolbar .input { flex: 1 1 180px; }
.toolbar select.input { flex: 1 1 140px; }
.sumbar { display: flex; gap: 6px 16px; font-size: 14px; color: var(--ink-2); margin: 12px 0 0; flex-wrap: wrap; }
.sumbar b { font: 700 16px var(--cond); color: var(--ink); }
.sumbar b.income { color: var(--green); }

.fab {
  position: fixed; right: 16px; bottom: calc(var(--nav-h) + var(--safe-b) + 16px); z-index: 25;
  height: 52px; padding: 0 20px 0 16px; border-radius: 8px; border: 0; background: var(--pen); color: var(--pen-text);
  display: flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 700;
  box-shadow: 0 3px 0 color-mix(in srgb, var(--pen) 55%, #000);
}
.fab svg { width: 20px; height: 20px; }
@media (min-width: 900px) { .fab { bottom: 28px; right: max(28px, calc(50% - 360px - 52px + 52px)); } }

/* ---------- Randnotizen ---------- */
.notice { padding: 10px 0 10px 14px; margin: 0 0 18px; border-left: 3px solid var(--pen); }
.notice.warn { border-left-color: var(--red); }
.notice b { display: block; margin-bottom: 1px; }
.notice .actions { margin-top: 8px; display: flex; gap: 8px; flex-wrap: wrap; }
.empty { text-align: center; padding: 36px 16px; color: var(--ink-2); }
.empty b { display: block; color: var(--ink); font: 700 22px var(--cond); margin-bottom: 6px; }

/* ---------- Import ---------- */
.drop {
  display: block; border: 1.5px dashed var(--pencil); border-radius: var(--radius); padding: 30px 18px;
  background: var(--sheet); cursor: pointer;
}
.drop.over { border-color: var(--pen); background: var(--pen-soft); }
.drop .drop-title { font: 700 24px/1.1 var(--cond); margin-bottom: 4px; }
.drop .btn { margin-top: 14px; pointer-events: none; }
.steps { margin: 0; padding-left: 22px; color: var(--ink-2); }
.steps li { margin: 6px 0; padding-left: 4px; }
.steps li::marker { font-family: var(--cond); font-weight: 700; color: var(--ink); }
.stats { display: flex; gap: 22px; margin: 6px 0 12px; flex-wrap: wrap; }
.stat b { display: block; font: 700 28px/1 var(--cond); }
.stat span { font-size: 14px; color: var(--ink-2); }
.imp-row { display: flex; gap: 12px; align-items: center; padding: 10px 12px; }
.imp-row:nth-child(even) { background: var(--band); }
.imp-row.off { opacity: .45; }
.imp-row input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--pen); flex: 0 0 20px; }
.tag { font-size: 12.5px; color: var(--ink-2); font-style: italic; }
.tag.pend { color: var(--red); }
.sticky-bottom {
  position: sticky; bottom: calc(var(--nav-h) + var(--safe-b) + 10px); margin-top: 14px; z-index: 5;
  background: var(--paper); padding: 8px 0; box-shadow: 0 -8px 12px -8px var(--paper);
}
@media (min-width: 900px) { .sticky-bottom { bottom: 0; } }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13.5px; color: var(--ink-2); margin-top: 10px; align-items: center; }
.legend .chip { margin: 0 4px 0 0; cursor: default; }
.legend > span { white-space: nowrap; }

/* ---------- Sheets ---------- */
.backdrop {
  position: fixed; inset: 0; background: rgba(16, 22, 34, .5); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease;
}
.sheet {
  background: var(--sheet); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto;
  border-radius: 12px 12px 0 0; padding: 10px 18px calc(18px + var(--safe-b)); animation: up .18s ease-out;
  border-top: 4px solid var(--pen);
}
@media (min-width: 640px) { .backdrop { align-items: center; } .sheet { border-radius: 10px; } }
.sheet .grab { width: 36px; height: 4px; border-radius: 2px; background: var(--rule); margin: 0 auto 12px; }
.sheet h3 { margin: 0 0 14px; font: 700 24px/1.15 var(--cond); }
.sheet p { line-height: 1.5; }
.sheet-actions { display: flex; gap: 10px; margin-top: 18px; }
.sheet-actions .btn { flex: 1; }
.catgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.catgrid button {
  border: 1.5px solid var(--rule); background: var(--sheet); border-radius: 8px; padding: 10px 10px 10px 8px;
  display: flex; align-items: center; gap: 10px; font-size: 14.5px; cursor: pointer; text-align: left; line-height: 1.2; min-height: 48px;
}
.catgrid button .tab { height: 26px; align-self: center; }
.catgrid button.sel { border-color: var(--ink); font-weight: 700; }
.kind-label { font: 700 16px var(--cond); color: var(--ink-2); margin: 16px 0 8px; }
.amount-input {
  font: 700 44px/1 var(--cond); text-align: right; border: 0; border-bottom: 4px double var(--rule);
  background: transparent; width: 100%; outline: none; padding: 10px 0 8px; margin: 6px 0 16px; color: var(--ink);
}
.amount-input:focus { border-bottom-color: var(--pen); }
.sheet .seg { margin-bottom: 4px; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatches button { width: 34px; height: 34px; border-radius: 6px; border: 3px solid transparent; cursor: pointer; }
.swatches button.sel { border-color: var(--ink); }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login .card { width: 100%; max-width: 380px; padding: 28px 22px 24px; border-top: 4px solid var(--pen); }
.logo { width: 52px; height: 52px; border-radius: 10px; display: block; margin-bottom: 18px; }
.login h1 { font: 700 32px/1 var(--cond); margin: 0 0 6px; }
.login p { margin: 0 0 22px; }
.err { border-left: 3px solid var(--red); color: var(--red); padding: 6px 0 6px 12px; margin-bottom: 14px; }

/* ---------- Diverses ---------- */
.list-plain { list-style: none; padding: 0; margin: 0 -16px; }
.list-plain li { display: flex; align-items: center; gap: 12px; padding: 11px 16px; }
.list-plain li:nth-child(even) { background: var(--band); }
.list-plain .grow { flex: 1; min-width: 0; }
.list-plain .amt { font: 700 18px var(--cond); }
#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--safe-b) + 84px); transform: translateX(-50%) translateY(12px);
  background: var(--ink); color: var(--sheet); padding: 11px 16px; border-radius: 6px; font-size: 15px;
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; z-index: 60; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.boot { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.spinner { width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--rule); border-top-color: var(--pen); animation: spin .8s linear infinite; }
.mapping-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.table-scroll { overflow-x: auto; font-size: 13px; }
.table-scroll table { border-collapse: collapse; }
.table-scroll td, .table-scroll th { border: 1px solid var(--rule); padding: 4px 6px; white-space: nowrap; max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
.prose { color: var(--ink-2); line-height: 1.55; margin: 0; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(30px); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- Schalter ---------- */
.toggles { border: 1px solid var(--rule); border-radius: var(--radius); overflow: hidden; }
.toggle { display: flex; align-items: center; gap: 14px; padding: 12px 14px; cursor: pointer; }
.toggle:nth-child(even) { background: var(--band); }
.toggle .t-text { flex: 1; min-width: 0; }
.toggle .t-text b { display: block; }
.toggle .t-text span { display: block; font-size: 14px; color: var(--ink-2); line-height: 1.35; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch { flex: 0 0 44px; height: 26px; border-radius: 13px; background: var(--rule); position: relative; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--sheet); transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.toggle input:checked + .switch { background: var(--pen); }
.toggle input:checked + .switch::after { transform: translateX(18px); }
.toggle input:focus-visible + .switch { outline: 2px solid var(--pen); outline-offset: 2px; }

/* ---------- Einführung ---------- */
.ob-progress { display: flex; gap: 6px; margin: 4px 0 12px; }
.ob-progress i { flex: 1; height: 4px; border-radius: 2px; background: var(--rule); }
.ob-progress i.on { background: var(--pen); }
.ob-demo { margin-top: 16px; pointer-events: none; }
.ob-demo .statement { margin-bottom: 0; }
.ob-demo .stmt-total .amt { font-size: 30px; }
.ob-demo .steps { color: var(--ink); }
