/* Ausgaben – Oberfläche
   Zuerst fürs Handy gebaut (eine Hand, Daumen unten), ab 720px ruhiger Desktop-Rahmen.
   Hell/dunkel über prefers-color-scheme. Keine externen Ressourcen, nur Systemschriften.
   Leitidee: Der Betrag steht wie auf einem Kassendisplay groß und rechtsbündig,
   der laufende Einkauf wächst als Bon darunter. Alles andere bleibt ruhig. */

:root {
  --bg: #edf0f3;
  --surface: #ffffff;
  --surface-2: #f0f3f6;        /* Feldflächen, gedrückte Zustände */
  --text: #12161b;
  --muted: #566170;
  --border: #dde2e8;
  --accent: #1a66b3;
  --accent-text: #ffffff;
  --accent-soft: #dcebfa;
  --ok: #1b7a45;
  --warn: #a4660f;
  --warn-bar: #e0a528;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --ok-soft: #e1f3e8;
  --info-soft: #dcebfa;
  --fix: #64748b;
  --paper: #fffdf6;            /* Bon */
  --paper-ink: #23262b;
  --radius: 14px;
  --radius-lg: 20px;
  --tap: 52px;
  --nav-h: 64px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-num: ui-rounded, "SF Pro Rounded", "Segoe UI", Roboto, system-ui, sans-serif;
  --font-receipt: ui-monospace, "SF Mono", "Roboto Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1114;
    --surface: #181c21;
    --surface-2: #232830;
    --text: #e9ecef;
    --muted: #a0a9b6;
    --border: #2f353e;
    --accent: #6fb2f0;
    --accent-text: #08131f;
    --accent-soft: #1b3047;
    --ok: #5fce8d;
    --warn: #f0b84a;
    --warn-bar: #e0a528;
    --danger: #ff8a80;
    --danger-soft: #3b1d1b;
    --ok-soft: #163322;
    --info-soft: #1b3047;
    --fix: #8b98ab;
    --paper: #23272d;
    --paper-ink: #e9ecef;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--font);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
a { color: var(--accent); }
code { background: var(--surface-2); padding: 0.1em 0.35em; border-radius: 5px; font-size: 0.9em; overflow-wrap: anywhere; }
h2 { margin: 0; }
p { margin: 0.6rem 0; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
a, button, summary, label, input, select { touch-action: manipulation; }

/* ---- Kopfzeile ---- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 0.75rem;
  min-height: 54px;
  padding: 0.4rem calc(1rem + env(safe-area-inset-right)) 0.4rem calc(1rem + env(safe-area-inset-left));
  padding-top: calc(0.4rem + env(safe-area-inset-top));
  background: var(--bg);
}
.menu-button {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 1rem;
  border-radius: var(--radius);
  background: var(--accent); color: var(--accent-text);
  font-weight: 600; text-decoration: none; white-space: nowrap;
}
.topbar-title { font-size: 1.45rem; font-weight: 750; letter-spacing: -0.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Am Handy übernimmt die Leiste unten die Navigation */
body.has-bottom-nav .menu-button { display: none; }

main {
  max-width: 880px; margin: 0 auto;
  padding: 0.25rem 0.75rem 2rem;
  padding-left: calc(0.75rem + env(safe-area-inset-left));
  padding-right: calc(0.75rem + env(safe-area-inset-right));
}
body.has-bottom-nav main { padding-bottom: calc(var(--nav-h) + 1.5rem + env(safe-area-inset-bottom)); }

/* ---- Flächen ---- */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 1rem;
  margin-bottom: 0.75rem;
}
.card-flush { padding: 0; overflow: hidden; }
.card-title { font-size: 1.05rem; font-weight: 700; margin-bottom: 0.75rem; }
.section-label { font-size: 0.85rem; font-weight: 600; color: var(--muted); margin: 0 0 0.4rem; }
.muted { color: var(--muted); font-size: 0.92rem; }
.center { text-align: center; }

/* ---- Meldungen ---- */
.flash {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap;
  padding: 0.75rem 1rem; margin-bottom: 0.75rem;
  border-radius: var(--radius-lg);
}
.flash-success { background: var(--ok-soft); }
.flash-error { background: var(--danger-soft); }
.flash-info { background: var(--info-soft); }
.flash-msg { flex: 1 1 10rem; font-weight: 550; }
.flash form { margin: 0; }
.flash .btn { background: var(--surface); }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--tap); padding: 0 1.15rem;
  border: 0; border-radius: var(--radius);
  background: var(--surface-2); color: var(--text);
  font: inherit; font-weight: 650; text-decoration: none; cursor: pointer;
  -webkit-appearance: none; appearance: none;
  transition: transform 80ms ease, filter 80ms ease;
}
.btn:active, .tile:active, .quick-btn:active, .icon-btn:active { transform: scale(0.97); filter: brightness(0.96); }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-secondary { background: var(--surface-2); }
.card .btn-secondary, .card .btn:not(.btn-primary):not(.btn-danger) { background: var(--surface-2); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-small { min-height: 44px; padding: 0 0.9rem; font-size: 0.92rem; }
.btn-big { width: 100%; min-height: 58px; font-size: 1.12rem; border-radius: 16px; }
.btn-block { display: flex; width: 100%; }
.btn.is-disabled { opacity: 0.4; pointer-events: none; }
.icon-btn {
  flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; padding: 0;
  border: 0; border-radius: 50%;
  background: var(--surface-2); color: var(--accent); cursor: pointer;
  transition: transform 80ms ease, filter 80ms ease;
}
form.is-submitting button[type="submit"] { opacity: 0.6; }

/* ---- Formulare ---- */
label, legend { display: block; padding: 0; font-size: 0.85rem; font-weight: 600; color: var(--muted); }
fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
input, select, textarea {
  display: block; width: 100%;
  min-height: var(--tap); margin-top: 0.3rem; padding: 0.55rem 0.85rem;
  border: 1.5px solid transparent; border-radius: var(--radius);
  background: var(--surface-2); color: var(--text);
  font: inherit; font-size: 16px; font-weight: 400;   /* 16px verhindert das Zoomen in iOS */
  -webkit-appearance: none; appearance: none;
}
select {
  padding-right: 2.2rem;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%;
  background-size: 6px 6px; background-repeat: no-repeat;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); background: var(--surface); }
input::placeholder { color: var(--muted); opacity: 0.75; }
input[type="color"] { padding: 0.25rem; }
input[type="checkbox"] {
  display: inline-block; flex: 0 0 auto; width: 1.5rem; height: 1.5rem; min-height: 0; margin: 0 0.6rem 0 0; padding: 0;
  vertical-align: middle; accent-color: var(--accent);
  -webkit-appearance: auto; appearance: auto;
}
input[type="date"] { min-width: 0; }
input[type="file"] { padding: 0.75rem; }
.card-flush input, .card-flush select, .row-edit input, .row-edit select { background: var(--surface); }
.check { display: flex; align-items: center; min-height: var(--tap); font-size: 1rem; font-weight: 450; color: var(--text); margin-bottom: 0.5rem; }
.field { margin-bottom: 0.85rem; min-width: 0; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr)); gap: 0 0.75rem; align-items: end; }
.field-row-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
/* Ungerade Anzahl: das letzte Feld füllt die Zeile statt eine Lücke zu lassen */
.field-row:not(.field-row-3) > .field:last-child:nth-child(odd):not(:only-child) { grid-column: 1 / -1; }
.inline-form { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin: 0.5rem 0; }
.inline-form input[type="search"] { flex: 1 1 10rem; width: auto; margin-top: 0; }
.inline-form .btn { flex: 1 1 auto; }

/* ---- Schnellerfassung ---- */
.entry-form { margin: 0; }
.entry-card { padding-top: 0.75rem; }

/* Betrag wie auf dem Kassendisplay: groß, rechtsbündig, Tabellenziffern */
.amount-hero {
  margin-bottom: 0.9rem; padding: 0.6rem 1rem 0.5rem;
  background: var(--surface-2); border-radius: 18px;
  border: 1.5px solid transparent;
}
.amount-hero:focus-within { border-color: var(--accent); background: var(--surface); }
.amount-line { display: flex; align-items: baseline; gap: 0.5rem; }
.amount-hero input {
  flex: 1 1 auto; min-width: 0; min-height: 0; margin: 0; padding: 0;
  border: 0; border-radius: 0; background: transparent;
  font-family: var(--font-num); font-size: clamp(2.6rem, 13vw, 3.4rem); font-weight: 700; line-height: 1.15;
  font-variant-numeric: tabular-nums; text-align: right; letter-spacing: -0.02em;
}
.amount-hero input:focus { background: transparent; }
.amount-unit { font-family: var(--font-num); font-size: 1.9rem; font-weight: 650; color: var(--muted); }
@keyframes amount-filled { from { color: var(--accent); } to { color: var(--text); } }
.amount-hero input.is-filled { animation: amount-filled 700ms ease-out; }

/* Schnellauswahl: zwei Zeilen, seitlich wischbar */
.quick-wrap { margin-bottom: 0.9rem; }
.quick-grid {
  display: grid; grid-auto-flow: column; grid-template-rows: repeat(2, auto); grid-auto-columns: minmax(9rem, 44%);
  gap: 0.5rem;
  margin: 0 -1rem; padding: 0 1rem 0.25rem;
  overflow-x: auto; scroll-snap-type: x proximity; scroll-padding-left: 1rem;
  scrollbar-width: none;
}
.quick-grid::-webkit-scrollbar { display: none; }
.quick-btn {
  scroll-snap-align: start;
  display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 0.1rem;
  min-height: 60px; padding: 0.5rem 0.8rem;
  border: 0; border-radius: var(--radius);
  background: var(--surface-2); color: var(--text);
  font: inherit; text-align: left; cursor: pointer;
  transition: transform 80ms ease, filter 80ms ease;
}
.quick-btn.is-fav { background: var(--accent-soft); }
.quick-name { font-weight: 650; line-height: 1.2; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.quick-price { font-size: 0.85rem; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Auswahl-Chips (Kategorie, Geschäft, Datum): ein Tipp statt Dropdown */
.chip-field { margin-bottom: 0.9rem; }
.chip-select { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.4rem; }
.chip-scroll { flex-wrap: nowrap; margin-left: -1rem; margin-right: -1rem; padding: 0 1rem; overflow-x: auto; scrollbar-width: none; }
.chip-scroll::-webkit-scrollbar { display: none; }
.chip-option { position: relative; display: inline-flex; flex: 0 0 auto; margin: 0; padding: 0; border: 0; background: none; font: inherit; color: inherit; cursor: pointer; }
.chip-option input { position: absolute; inset: 0; width: 100%; height: 100%; min-height: 0; margin: 0; opacity: 0; cursor: pointer; }
.chip-option span {
  display: inline-flex; align-items: center; min-height: 42px; padding: 0 0.8rem;
  border-radius: 999px; background: var(--surface-2); color: var(--text);
  font-size: 0.92rem; font-weight: 550; white-space: nowrap;
  transition: background 100ms ease, color 100ms ease;
}
.chip-option input:checked + span, .chip-option.is-on span { background: var(--accent); color: var(--accent-text); }
.chip-option input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
.chip-field > input { margin-top: 0.5rem; }
.date-line { display: flex; align-items: center; gap: 0.45rem; margin-top: 0.4rem; }
.date-line input { flex: 1 1 8rem; margin-top: 0; min-height: 44px; padding-top: 0.3rem; padding-bottom: 0.3rem; }

.more-fields > summary {
  display: flex; align-items: center; min-height: 44px;
  font-size: 0.95rem; font-weight: 600; color: var(--accent); cursor: pointer; list-style: none;
}
.more-fields > summary::-webkit-details-marker { display: none; }
.more-fields > summary::before { content: '+'; display: inline-block; width: 1.2rem; font-weight: 700; }
.more-fields[open] > summary::before { content: '−'; }
.more-fields .field { margin-bottom: 0.25rem; }

/* "Hinzufügen" bleibt in Daumenreichweite über der Navigationsleiste */
.submit-bar {
  position: sticky; z-index: 15;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
  margin: -0.25rem -0.75rem 0.75rem; padding: 0.6rem 0.75rem 0.6rem;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}

/* Laufender Einkauf */
.trip-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  background: var(--accent); color: var(--accent-text);
  border-radius: var(--radius-lg); padding: 0.7rem 0.75rem 0.7rem 1rem; margin-bottom: 0.75rem;
}
.trip-banner form { margin: 0; }
.trip-banner .btn { background: rgba(255, 255, 255, 0.22); color: inherit; }
.trip-info { min-width: 0; }
.trip-label { font-size: 0.85rem; opacity: 0.9; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trip-total { font-family: var(--font-num); font-size: 1.6rem; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }

/* Der Bon: wächst mit jedem Posten, gezackte Abrisskante unten */
.receipt {
  --zag: 14px;
  margin: 0 0.75rem 1rem; padding: 0.9rem 1rem calc(0.9rem + var(--zag));
  background: var(--paper); color: var(--paper-ink);
  font-family: var(--font-receipt); font-size: 0.9rem;
  -webkit-mask: conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) 50% / var(--zag) 100%;
          mask: conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) 50% / var(--zag) 100%;
}
.receipt-head { display: flex; justify-content: space-between; gap: 1rem; padding-bottom: 0.5rem; border-bottom: 1px dashed currentColor; font-weight: 700; }
.receipt-lines { list-style: none; margin: 0; padding: 0.5rem 0; }
.receipt-lines li, .receipt-total { display: flex; justify-content: space-between; gap: 1rem; padding: 0.12rem 0; }
.receipt-name { min-width: 0; overflow-wrap: anywhere; }
.receipt-amount { white-space: nowrap; font-variant-numeric: tabular-nums; }
.receipt-total { padding-top: 0.5rem; border-top: 1px dashed currentColor; font-size: 1.05rem; font-weight: 700; }

/* ---- Menü: am Handy eine Liste über die volle Breite, ab 720px Kacheln ---- */
.tiles { display: grid; grid-template-columns: 1fr; gap: 0.5rem; }
.tile {
  display: flex; align-items: center; gap: 0.9rem;
  min-height: 72px; padding: 0.7rem 1rem;
  background: var(--surface); border-radius: var(--radius-lg);
  color: var(--text); text-decoration: none;
  transition: transform 80ms ease, filter 80ms ease;
}
.tile::after { content: ''; flex: 0 0 auto; width: 0.55rem; height: 0.55rem; margin-left: auto; border-right: 2px solid var(--muted); border-top: 2px solid var(--muted); transform: rotate(45deg); opacity: 0.6; }
.tile-icon { flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; width: 46px; height: 46px; border-radius: 14px; background: var(--surface-2); font-size: 1.45rem; line-height: 1; }
.tile-text { display: flex; flex-direction: column; min-width: 0; }
.tile-label { font-size: 1.05rem; font-weight: 700; }
.tile-sub { font-size: 0.85rem; color: var(--muted); line-height: 1.3; }

/* ---- Kennzahlen ---- */
.stat-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; margin-bottom: 0.75rem; }
.stat { background: var(--surface); border-radius: var(--radius-lg); padding: 0.8rem 1rem; min-width: 0; }
.stat-label { font-size: 0.85rem; color: var(--muted); }
.stat-value { font-family: var(--font-num); font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.stat-sub { font-size: 0.8rem; color: var(--muted); }
.stat-hero { grid-column: 1 / -1; padding: 1rem 1.1rem; }
.stat-hero .stat-value { font-size: clamp(2.2rem, 11vw, 2.9rem); line-height: 1.15; }
.stat-grid > .stat:only-child { grid-column: 1 / -1; }
.state-ok { color: var(--ok); }
.state-warn { color: var(--warn); }
.state-over { color: var(--danger); }

/* ---- Reiter (Segmente) und Zeitraum ---- */
.tabs { display: flex; gap: 4px; margin-bottom: 0.75rem; padding: 4px; background: var(--surface-2); border-radius: 16px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 1 0 auto; display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 0.9rem;
  border-radius: 12px; color: var(--muted); text-decoration: none; font-weight: 650; font-size: 0.95rem; white-space: nowrap;
}
.tab.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(18, 22, 27, 0.14); }
.period-nav { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.75rem; }
.period-nav .btn { width: var(--tap); padding: 0; font-size: 1.5rem; background: var(--surface); border-radius: 50%; }
.period-title { font-size: 1.25rem; font-weight: 750; }

/* ---- Listen ---- */
.entry-list, .plain-list, .legend, .rank-list { list-style: none; margin: 0; padding: 0; }
.entry { display: flex; align-items: center; gap: 0.7rem; min-height: 60px; padding: 0.5rem 0; border-bottom: 1px solid var(--border); }
.entry:last-child { border-bottom: 0; }
.entry-wrap { flex-wrap: wrap; }
.entry-main { flex: 1 1 0; min-width: 0; display: block; }
.entry-title { display: block; font-weight: 600; overflow-wrap: anywhere; }
.entry-sub { display: block; font-size: 0.85rem; color: var(--muted); overflow-wrap: anywhere; }
.entry-amount { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.is-archived { opacity: 0.6; }
.dot { display: inline-block; flex: 0 0 auto; width: 0.75rem; height: 0.75rem; border-radius: 50%; vertical-align: baseline; }

.plain-list li { display: flex; justify-content: space-between; gap: 0.75rem; padding: 0.55rem 0; border-bottom: 1px solid var(--border); }
.plain-list li:last-child { border-bottom: 0; }
.plain-list strong { white-space: nowrap; font-variant-numeric: tabular-nums; }
.plain-list .total { font-weight: 700; }

.rank-list li { padding: 0.45rem 0; }
.rank-head { display: flex; justify-content: space-between; gap: 0.75rem; }
.rank-head strong { white-space: nowrap; font-variant-numeric: tabular-nums; }
.meter { height: 6px; margin-top: 0.3rem; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.meter-fill { height: 100%; background: var(--accent); border-radius: 3px; }

/* ---- Aufklappbare Zeilen (Verlauf, Verwaltung) ---- */
.row { border-bottom: 1px solid var(--border); }
.row:last-of-type { border-bottom: 0; }
.row > summary {
  display: flex; align-items: center; gap: 0.7rem;
  min-height: 64px; padding: 0.6rem 1rem;
  cursor: pointer; list-style: none;
}
.row > summary::-webkit-details-marker { display: none; }
.row[open] > summary { background: var(--surface-2); }
.row-edit { padding: 0.9rem 1rem 1rem; background: var(--surface-2); display: flex; flex-direction: column; gap: 0.6rem; }
.row-edit form { margin: 0; }
.row-edit .btn { width: 100%; }
.row-edit .btn:not(.btn-primary):not(.btn-danger) { background: var(--surface); }
.card:not(.card-flush) > .row > summary { padding-left: 0; padding-right: 0; }
.card:not(.card-flush) > .row[open] > summary { margin: 0 -1rem; padding-left: 1rem; padding-right: 1rem; }
.card:not(.card-flush) > .row > .row-edit { margin: 0 -1rem; }

.filter-box > summary { min-height: 44px; display: flex; align-items: center; font-weight: 700; cursor: pointer; list-style: none; }
.filter-box > summary::-webkit-details-marker { display: none; }
.filter-box > summary::after { content: '▾'; margin-left: auto; padding-left: 0.5rem; color: var(--muted); }
.filter-box[open] > summary::after { content: '▴'; }
.filter-form { margin-top: 0.5rem; }
.chips { display: flex; gap: 0.45rem; margin: 0.5rem -1rem 0.75rem; padding: 0 1rem; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; display: inline-flex; align-items: center; min-height: 44px; padding: 0 0.95rem;
  border-radius: 999px; background: var(--surface-2); color: var(--text);
  text-decoration: none; font-size: 0.95rem; font-weight: 550; white-space: nowrap;
}
.summary-bar {
  position: sticky; top: calc(54px + env(safe-area-inset-top)); z-index: 5;
  display: flex; justify-content: space-between; align-items: baseline; gap: 0.75rem;
  margin: 0 -0.75rem 0.5rem; padding: 0.5rem 1.25rem;
  background: var(--bg); font-variant-numeric: tabular-nums;
}
.summary-bar strong { font-family: var(--font-num); font-size: 1.15rem; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin: 0.75rem 0; }
.pager .btn { background: var(--surface); }
.pager-info { color: var(--muted); }

.badge { display: inline-block; padding: 0.1rem 0.55rem; border-radius: 999px; background: var(--surface-2); font-size: 0.78rem; font-weight: 700; white-space: nowrap; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-dup { background: var(--info-soft); }
.badge-err { background: var(--danger-soft); color: var(--danger); white-space: normal; }

/* ---- Verwaltung ---- */
.manage-form { margin: 0; }
.manage-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.5rem; }
.manage-actions form { margin: 0; flex: 1 1 auto; }
.manage-actions .btn { width: 100%; }
.entry .manage-actions { flex: 1 0 100%; margin-top: 0; }

/* ---- Budgets ---- */
.budget { margin-bottom: 1rem; }
.budget-name { margin-bottom: 0.3rem; font-weight: 550; }
.progress { height: 12px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.progress-bar { height: 100%; border-radius: 6px; }
.progress-bar.ok { background: var(--ok); }
.progress-bar.warn { background: var(--warn-bar); }
.progress-bar.over { background: var(--danger); }
.progress-text { display: flex; justify-content: space-between; gap: 0.5rem; flex-wrap: wrap; font-size: 0.85rem; color: var(--muted); margin-top: 0.25rem; font-variant-numeric: tabular-nums; }
.progress-text .state-warn, .progress-text .state-over, .progress-text .state-ok { font-weight: 700; }

/* ---- Diagramme ---- */
.donut-wrap { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem; }
.donut { flex: 0 0 auto; width: min(230px, 62vw); height: auto; margin: 0 auto; }
.donut-ring { stroke: var(--surface-2); }
.donut-top { font-family: var(--font-num); font-size: 4.4px; font-weight: 700; fill: var(--text); }
.donut-bottom { font-size: 2.6px; fill: var(--muted); }
.legend { flex: 1 1 14rem; }
.legend li { display: grid; grid-template-columns: auto 1fr auto 3.2rem; align-items: center; gap: 0.5rem; min-height: 44px; border-bottom: 1px solid var(--border); }
.legend li:last-child { border-bottom: 0; }
.legend-name { overflow-wrap: anywhere; }
.legend-value { font-weight: 650; white-space: nowrap; font-variant-numeric: tabular-nums; }
.legend-pct { text-align: right; white-space: nowrap; color: var(--muted); font-variant-numeric: tabular-nums; }

.chart { overflow-x: auto; }
.bars { display: block; width: 100%; min-width: 300px; max-width: 720px; height: auto; margin: 0 auto; }
.bars .grid { stroke: var(--border); stroke-width: 1; stroke-dasharray: 3 3; }
.bars .axis { stroke: var(--muted); stroke-width: 1; }
.bars .grid-label, .bars .bar-label, .bars .bar-sub { font-size: 10px; fill: var(--muted); }
.bars .bar-value { font-size: 9.5px; fill: var(--text); font-weight: 600; }
.bars .bar-a { fill: var(--accent); opacity: 0.75; }
.bars .bar-b { fill: var(--fix); opacity: 0.75; }
.bars .bar-hl .bar-a, .bars .bar-hl .bar-b { opacity: 1; }
.bars .bar-hl .bar-label { fill: var(--text); font-weight: 700; }
.chart-key { font-size: 0.85rem; color: var(--muted); }
.key { display: inline-block; width: 0.8rem; height: 0.8rem; border-radius: 3px; margin: 0 0.25rem 0 0.75rem; vertical-align: -1px; }
.key:first-child { margin-left: 0; }
.key-a { background: var(--accent); }
.key-b { background: var(--fix); }

/* ---- Tabellen ---- */
.table-wrap { overflow-x: auto; margin: 0.5rem -1rem; padding: 0 1rem; }
.table { border-collapse: collapse; width: 100%; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.table th, .table td { padding: 0.55rem 0.55rem; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.table thead th { color: var(--muted); font-size: 0.82rem; font-weight: 600; }
.table .num { text-align: right; }
.table .zero { color: var(--muted); }
.table .strong, .table tfoot th { font-weight: 700; }
.table-year tbody th, .table-year tfoot th { position: sticky; left: -1rem; background: var(--surface); font-weight: 600; }
.table-year thead th:first-child { position: sticky; left: -1rem; background: var(--surface); }

/* ---- Anmeldung ---- */
.login-card { max-width: 26rem; margin: 1.5rem auto; padding: 1.5rem 1.25rem; }
.login-logo { display: flex; justify-content: center; margin-bottom: 0.5rem; }
.login-logo img { border-radius: 16px; }
.steps { margin: 0.5rem 0 0; padding-left: 1.2rem; }
.steps li { margin: 0.4rem 0; }

/* ---- Untere Navigationsleiste ---- */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex;
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--surface);
  box-shadow: 0 -1px 0 var(--border);
}
.bottom-nav a {
  flex: 1 1 0; min-width: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: var(--nav-h);
  color: var(--muted); text-decoration: none; font-size: 0.74rem; font-weight: 650;
}
.bottom-nav svg { display: block; box-sizing: content-box; padding: 4px 20px; border-radius: 999px; transition: background 120ms ease; }
.bottom-nav a.active { color: var(--text); }
.bottom-nav a.active svg { background: var(--accent-soft); color: var(--accent); }
.bottom-nav a:active svg { background: var(--surface-2); }

/* Bildschirmtastatur offen (Android verkleinert das Fenster): Leiste weg, mehr Platz zum Tippen */
@media (max-height: 520px) and (max-width: 719px) {
  .bottom-nav { display: none; }
  .submit-bar { bottom: 0; }
  body.has-bottom-nav main { padding-bottom: 1rem; }
}

/* Als installierte App: Bedienelemente nicht versehentlich markieren */
.is-standalone .btn, .is-standalone .tile, .is-standalone .quick-btn, .is-standalone .bottom-nav,
.is-standalone .tab, .is-standalone .chip-option, .is-standalone .chip { -webkit-user-select: none; user-select: none; }

/* ======================================================================
   Ab 720px: Leiste unten entfällt, Menü-Knopf oben, Flächen mit Rahmen
   ====================================================================== */
@media (min-width: 720px) {
  .bottom-nav { display: none; }
  body.has-bottom-nav .menu-button { display: inline-flex; }
  body.has-bottom-nav main { padding-bottom: 2rem; }
  .topbar { background: var(--surface); box-shadow: 0 1px 0 var(--border); }
  .topbar-title { font-size: 1.2rem; }
  main { padding: 1rem; }
  .card, .stat, .tile { border: 1px solid var(--border); }
  .tiles { grid-template-columns: repeat(3, 1fr); gap: 0.75rem; }
  .tile { flex-direction: column; align-items: flex-start; justify-content: flex-end; gap: 0.5rem; min-height: 132px; padding: 1rem; }
  .tile::after { display: none; }
  .tile-icon { margin-bottom: auto; }
  .stat-grid { grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); }
  .stat-hero { grid-column: auto; }
  .stat-hero .stat-value { font-size: 1.6rem; }
  .entry-form { max-width: 34rem; }
  .field-row:not(.field-row-3) > .field:last-child:nth-child(odd):not(:only-child) { grid-column: auto; }
  .quick-grid { grid-auto-flow: row; grid-template-rows: none; grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr)); margin: 0; padding: 0; overflow: visible; }
  .chip-scroll, .chips { flex-wrap: wrap; margin-left: 0; margin-right: 0; padding: 0; overflow: visible; }
  .submit-bar { position: static; margin: 0 0 0.75rem; padding: 0; background: none; }
  .receipt { max-width: 22rem; margin-left: 0; }
  .summary-bar { position: static; margin: 0 0 0.5rem; padding: 0.25rem 0.5rem; }
  .row-edit .btn, .manage-actions .btn { width: auto; }
  .manage-actions form { flex: 0 0 auto; }
  .inline-form .btn { flex: 0 0 auto; }
  .table-wrap { margin: 0.5rem 0; padding: 0; }
  .table-year tbody th, .table-year tfoot th, .table-year thead th:first-child { left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
