/*
 * Haushaltsbuch. Gestaltet nach den Apple Human Interface Guidelines:
 * - Erscheinungsbild folgt nur der Systemeinstellung (kein eigener Hell/Dunkel-Schalter)
 * - Schriftgrößen in rem; auf iPhone/iPad übernimmt -apple-system-body die Textgröße
 *   aus den Systemeinstellungen (Dynamic Type)
 * - Bedienelemente mindestens 44 × 44 pt bei Touch
 * - Kontraste berechnet: Text ≥ 4,5:1, Grafik ≥ 3:1, hell wie dunkel
 * - Reduzierte Bewegung, reduzierte Transparenz und erhöhter Kontrast werden beachtet
 */

:root {
  --bg: #f2f3f7;
  --surface: #ffffff;
  --surface-2: #eceef3;
  --separator: #dcdfe6;
  --text: #15181f;
  --muted: #5b6272;           /* 6,1:1 auf surface, 5,3:1 auf surface-2 */
  --accent: #3f3fd1;          /* 7,4:1 auf surface */
  --on-accent: #ffffff;       /* 7,4:1 auf accent */
  --accent-soft: #e8e8fb;
  --income: #0a7a50;          /* 5,4:1 */
  --income-soft: #e3f4ec;
  --expense: #c42847;         /* 5,6:1 */
  --expense-soft: #fbe7eb;
  --chart-income: #0a7a50;
  --chart-expense: #e0607a;   /* 3,4:1 auf surface und deutlich heller als Einnahmen */
  --grid: #e6e8ee;
  --glass: rgba(255, 255, 255, .72);
  --scrim: rgba(12, 14, 20, .38);
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 6px 20px rgba(16, 24, 40, .06);
  --radius: 1rem;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable Text", "Segoe UI", Roboto, system-ui, sans-serif;
  --display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI Variable Display", "Segoe UI", Roboto, system-ui, sans-serif;
  --control: 2.25rem;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0c10;
    --surface: #17191f;
    --surface-2: #20232b;
    --separator: #2c303a;
    --text: #eef0f5;
    --muted: #a0a6b4;         /* 7,2:1 */
    --accent: #8c8cff;        /* 6,1:1 */
    --on-accent: #0b0c10;     /* dunkle Schrift: weiß käme nur auf 2,9:1 */
    --accent-soft: #262852;
    --income: #3fd497;
    --income-soft: #12322a;
    --expense: #ff7d93;
    --expense-soft: #3b1a23;
    --chart-income: #3fd497;
    --chart-expense: #c9506a;
    --grid: #252831;
    --glass: rgba(23, 25, 31, .72);
    --scrim: rgba(0, 0, 0, .55);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .28);
  }
}

@media (prefers-contrast: more) {
  :root { --separator: #8a90a0; --muted: #3f4552; --grid: #c3c7d1; --glass: var(--surface); }
}
@media (prefers-contrast: more) and (prefers-color-scheme: dark) {
  :root { --separator: #6b7180; --muted: #c9cedb; --grid: #3d424e; }
}

/* Touch: größere Ziele; auf iOS die Systemtextgröße (Dynamic Type) übernehmen. */
@media (pointer: coarse) {
  :root { --control: 2.75rem; }
  @supports (font: -apple-system-body) {
    html { font: -apple-system-body; }
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; font-family: var(--display); letter-spacing: -.01em; }
h1 { font-size: 1.75rem; font-weight: 700; }
h2 { font-size: 1.25rem; font-weight: 650; }
h3 { font-size: 1.0625rem; font-weight: 600; }
p { margin: 0; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
.pos { color: var(--income); }
.neg { color: var(--expense); }
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.btn svg, .nav svg, .kpi-icon svg, .search svg, .delta svg, .fab svg {
  width: 1.25em; height: 1.25em; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* --- Bedienelemente ------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: var(--control); padding: 0 1rem; border-radius: 999px; border: 0;
  font: inherit; font-size: 1rem; font-weight: 600; cursor: pointer; color: var(--accent);
  background: var(--accent-soft); text-decoration: none; white-space: nowrap;
  transition: filter .15s, background .15s;
}
.btn:hover { filter: brightness(.97); }
.btn:active { filter: brightness(.92); }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-plain { background: transparent; color: var(--accent); padding: 0 .625rem; }
.btn-plain:hover { background: var(--accent-soft); filter: none; }
.btn-gray { background: var(--surface-2); color: var(--text); }
.btn-destructive-plain { background: transparent; color: var(--expense); }
.btn-destructive-plain:hover { background: var(--expense-soft); filter: none; }
.btn-icon { width: var(--control); padding: 0; }
.btn[disabled] { opacity: .45; cursor: default; }

.field { display: flex; flex-direction: column; gap: .375rem; flex: 1; min-width: 0; }
.field > span { font-size: .875rem; color: var(--muted); font-weight: 500; }
.field .hint { font-size: .875rem; color: var(--muted); }
input, select {
  min-height: var(--control); padding: 0 .75rem; border-radius: .625rem; border: 1px solid var(--separator);
  background: var(--surface); color: var(--text); font: inherit; font-size: 1rem; min-width: 0;
}
.field-row { display: flex; gap: .75rem; }
.error { color: var(--expense); font-size: .9375rem; }

/* --- Anmeldung ----------------------------------------------------------- */
.auth {
  min-height: 100vh; min-height: 100dvh; display: grid; place-items: center;
  padding: max(1.5rem, env(safe-area-inset-top)) 1rem max(1.5rem, env(safe-area-inset-bottom));
}
.auth-card { width: 100%; max-width: 24rem; display: flex; flex-direction: column; gap: 1rem; }
.auth-card .brand-mark { width: 4rem; height: 4rem; border-radius: 1.1rem; margin: 0 auto .25rem; }
.auth-card h1 { text-align: center; }
.auth-card > p { text-align: center; color: var(--muted); margin-top: -.5rem; }
.auth-card .group { background: var(--surface); border-radius: var(--radius); padding: 1rem; display: flex; flex-direction: column; gap: .875rem; box-shadow: var(--shadow); }
.auth-card .btn { min-height: 3rem; }

/* --- Rahmen -------------------------------------------------------------- */
.brand { display: flex; align-items: center; gap: .625rem; font-weight: 700; font-size: 1.0625rem; }
.brand-mark { width: 1.875rem; height: 1.875rem; border-radius: .5rem; flex: none; background: url(icon.svg) center / cover; }

.shell { display: grid; grid-template-columns: 15rem 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; padding: 1.25rem .75rem;
  border-right: 1px solid var(--separator); background: var(--surface);
  display: flex; flex-direction: column; gap: 1.5rem;
}
.sidebar .brand { padding: 0 .625rem; }
.nav { display: flex; flex-direction: column; gap: .125rem; }
.nav a {
  display: flex; align-items: center; gap: .75rem; min-height: 2.25rem; padding: 0 .75rem; border-radius: .5rem;
  color: var(--text); text-decoration: none; font-weight: 500;
}
.nav a svg { color: var(--accent); }
.nav a:hover { background: var(--surface-2); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidebar-foot { margin-top: auto; padding: 0 .75rem; font-size: .875rem; color: var(--muted); }

.main { min-width: 0; padding: 1.5rem 2rem 3rem; max-width: 82rem; width: 100%; justify-self: center; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.topbar-actions { display: flex; align-items: center; gap: .75rem; }
.month-switch { display: flex; align-items: center; gap: .25rem; }
.month-label {
  min-width: 10rem; min-height: var(--control); border: 0; background: none; color: var(--text); font: inherit;
  font-weight: 600; font-size: 1.0625rem; cursor: pointer; border-radius: .5rem; padding: 0 .5rem;
}
.month-label:hover { background: var(--surface-2); }
.month-switch.inactive .month-label { color: var(--muted); }

.view { display: flex; flex-direction: column; gap: 1.25rem; }
.view.enter { animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.card { position: relative; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; min-width: 0; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: .5rem .75rem; margin-bottom: 1rem; flex-wrap: wrap; }
.card-head p { font-size: .875rem; color: var(--muted); margin-top: .125rem; }

/* --- Kennzahlen ---------------------------------------------------------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; }
.kpi { display: flex; flex-direction: column; gap: .5rem; }
.kpi-top { display: flex; align-items: center; gap: .5rem; color: var(--muted); font-size: .9375rem; font-weight: 500; }
.kpi-icon { width: 1.875rem; height: 1.875rem; border-radius: .5rem; display: grid; place-items: center; flex: none; }
.kpi-icon svg { width: 1.0625rem; height: 1.0625rem; }
.kpi-icon.inc { background: var(--income-soft); color: var(--income); }
.kpi-icon.exp { background: var(--expense-soft); color: var(--expense); }
.kpi-icon.bal { background: var(--accent-soft); color: var(--accent); }
.kpi-value { font-family: var(--display); font-size: 1.75rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.15; overflow-wrap: anywhere; }
.kpi-sub { font-size: .875rem; color: var(--muted); display: flex; align-items: center; gap: .375rem; flex-wrap: wrap; }
.delta { display: inline-flex; align-items: center; gap: .125rem; padding: .0625rem .5rem; border-radius: 99px; font-weight: 600; font-size: .8125rem; }
.delta svg { width: .875em; height: .875em; stroke-width: 2.75; }
.delta.good { background: var(--income-soft); color: var(--income); }
.delta.bad { background: var(--expense-soft); color: var(--expense); }
.delta.flat { background: var(--surface-2); color: var(--muted); }
.meter { height: .375rem; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin-top: .25rem; }
.meter > span { display: block; height: 100%; border-radius: inherit; background: var(--accent); }

.grid-2-1 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 1rem; }
.grid-1-1 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }

/* --- Diagramme (in echten Pixeln gezeichnet, Text bleibt lesbar) ---------- */
.chart-box { position: relative; width: 100%; min-height: 12rem; }
.chart { display: block; width: 100%; overflow: visible; }
.chart text { fill: var(--muted); font-size: .75rem; font-family: var(--font); }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .zeroline { stroke: var(--separator); stroke-width: 1.5; }
.chart .bar-inc { fill: var(--chart-income); }
.chart .bar-exp { fill: var(--chart-expense); }
.chart .group { cursor: pointer; outline: none; }
.chart .group .hit { fill: transparent; }
.chart .group:hover .hit { fill: var(--surface-2); }
.chart .group:focus-visible .hit { fill: var(--surface-2); stroke: var(--accent); stroke-width: 2; }
.chart .group.dim path { opacity: .4; }
.chart .group.sel text { fill: var(--text); font-weight: 700; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--surface); stroke: var(--accent); stroke-width: 2.5; }
.legend-inline { display: flex; gap: 1rem; font-size: .875rem; color: var(--muted); }
.legend-inline i { display: inline-block; width: .75rem; height: .75rem; border-radius: .1875rem; margin-right: .375rem; vertical-align: -.0625rem; }
.legend-inline i.inc { background: var(--chart-income); }
.legend-inline i.exp { background: var(--chart-expense); }

.donut-wrap { display: flex; flex-direction: column; align-items: center; gap: 1.25rem; }
.donut { width: 11.875rem; height: 11.875rem; flex: none; }
.donut circle { fill: none; stroke-width: 22; }
.donut .track { stroke: var(--surface-2); }
.donut text { text-anchor: middle; font-family: var(--font); }
.donut .d-label { fill: var(--muted); font-size: 12px; }
.donut .d-value { fill: var(--text); font-size: 17px; font-weight: 700; }
.legend { width: 100%; display: flex; flex-direction: column; gap: .5rem; margin: 0; padding: 0; list-style: none; }
.legend li { display: grid; grid-template-columns: .75rem minmax(0, 1fr) auto 2.75rem; align-items: center; gap: .625rem; font-size: .9375rem; }
.legend .dot { width: .75rem; height: .75rem; border-radius: .1875rem; }
.legend .pct { color: var(--muted); font-size: .8125rem; text-align: right; }
.legend .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tooltip {
  position: fixed; z-index: 50; pointer-events: none; background: var(--text); color: var(--bg);
  padding: .5rem .75rem; border-radius: .625rem; font-size: .875rem; line-height: 1.45; box-shadow: var(--shadow);
  transform: translate(-50%, calc(-100% - .75rem)); white-space: nowrap;
}

/* --- Listen -------------------------------------------------------------- */
.tx-list { display: flex; flex-direction: column; }
.tx {
  display: grid; grid-template-columns: 2.5rem minmax(0, 1fr) auto; align-items: center; gap: .75rem;
  min-height: 3.5rem; padding: .5rem; border-radius: .75rem; cursor: pointer;
  background: none; border: 0; font: inherit; color: inherit; text-align: left; width: 100%;
}
.tx:hover { background: var(--surface-2); }
.tx-avatar {
  width: 2.5rem; height: 2.5rem; border-radius: .75rem; display: grid; place-items: center;
  font-weight: 700; font-size: .875rem; color: #fff; text-shadow: 0 1px 1px rgba(0, 0, 0, .3);
}
.tx-main { min-width: 0; }
.tx-title { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-meta { font-size: .875rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-amount { font-weight: 650; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.day-head {
  display: flex; justify-content: space-between; gap: 1rem; padding: 1rem .5rem .375rem;
  font-size: .875rem; color: var(--muted); font-weight: 600; margin: 0;
}
.day-head:first-child { padding-top: 0; }

.toolbar { display: flex; gap: .625rem; flex-wrap: wrap; align-items: center; }
.search { position: relative; flex: 1 1 14rem; }
.search svg { position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { width: 100%; padding-left: 2.5rem; background: var(--surface-2); border-color: transparent; }
.segmented { display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); border-radius: .625rem; padding: .125rem; }
.segmented button, .segmented label span {
  display: flex; align-items: center; justify-content: center; min-height: calc(var(--control) - .25rem);
  border: 0; background: none; font: inherit; font-size: .9375rem; font-weight: 550; color: var(--text);
  padding: 0 .875rem; border-radius: .5rem; cursor: pointer;
}
.segmented [aria-pressed="true"], .segmented input:checked + span {
  background: var(--surface); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); font-weight: 650;
}
.segmented label { position: relative; display: block; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; min-height: 0; }
.segmented input:focus-visible + span { outline: 3px solid var(--accent); }
.switch { display: inline-flex; align-items: center; gap: .625rem; font-size: .9375rem; cursor: pointer; user-select: none; min-height: var(--control); }
.switch input {
  appearance: none; -webkit-appearance: none; width: 3.1875rem; height: 1.9375rem; min-height: 0; padding: 0; flex: none;
  border-radius: 99px; background: var(--surface-2); border: 1px solid var(--separator); position: relative; cursor: pointer; transition: background .2s;
}
.switch input::after {
  content: ""; position: absolute; top: .125rem; left: .125rem; width: 1.5625rem; height: 1.5625rem; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .2s;
}
.switch input:checked { background: var(--income); border-color: var(--income); }
.switch input:checked::after { transform: translateX(1.25rem); }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; }
.stats > div { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: .875rem 1rem; }
.stats .label { font-size: .875rem; color: var(--muted); font-weight: 500; }
.stats .value { font-weight: 700; font-size: 1.125rem; font-variant-numeric: tabular-nums; }

.empty { text-align: center; padding: 2.25rem 1rem; color: var(--muted); }
.empty h3 { color: var(--text); margin-bottom: .25rem; }
.empty .btn { margin-top: 1rem; }

/* --- Gruppierte Listen (Kategorien, Einstellungen) ----------------------- */
.list-group { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.list-head { padding: 1rem 1.25rem .5rem; }
.list-head p { font-size: .875rem; color: var(--muted); margin-top: .125rem; }
.row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; gap: .5rem; align-items: center; padding: .25rem .75rem .25rem 1rem; min-height: 3rem; position: relative; }
.row + .row::before { content: ""; position: absolute; top: 0; right: 0; left: 3.75rem; border-top: 1px solid var(--separator); }
.row input[type="text"] { border-color: transparent; background: transparent; padding: 0 .5rem; }
.row input[type="text"]:hover, .row input[type="text"]:focus { border-color: var(--separator); background: var(--surface); }
.swatch-wrap { width: var(--control); height: var(--control); display: grid; place-items: center; flex: none; }
.swatch { appearance: none; -webkit-appearance: none; width: 1.75rem; height: 1.75rem; min-height: 0; padding: 0; border: 0; border-radius: .5rem; cursor: pointer; background: none; }
.swatch::-webkit-color-swatch-wrapper { padding: 0; }
.swatch::-webkit-color-swatch { border: 0; border-radius: .5rem; }
.swatch::-moz-color-swatch { border: 0; border-radius: .5rem; }
.count { font-size: .875rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.row-add { border-top: 1px solid var(--separator); grid-template-columns: auto minmax(0, 1fr) auto; }

.settings { max-width: 40rem; display: flex; flex-direction: column; gap: 1.5rem; }
.settings .body { padding: .25rem 1.25rem 1.25rem; display: flex; flex-direction: column; gap: .75rem; }
.settings .body > p { color: var(--muted); font-size: .9375rem; }
.settings .actions { display: flex; gap: .625rem; flex-wrap: wrap; }

/* --- Blatt (Sheet) und Hinweis ------------------------------------------- */
.sheet, .alert {
  border: 0; padding: 0; background: var(--surface); color: var(--text);
  box-shadow: 0 24px 64px rgba(0, 0, 0, .28); max-height: calc(100dvh - 2rem);
}
.sheet { width: min(30rem, calc(100vw - 2rem)); border-radius: 1.25rem; }
.sheet::backdrop, .alert::backdrop { background: var(--scrim); }
.sheet[open] { animation: rise .24s cubic-bezier(.2, .8, .2, 1); }
@keyframes rise { from { opacity: 0; transform: translateY(1.5rem); } to { opacity: 1; transform: none; } }
.sheet form { display: flex; flex-direction: column; gap: 1rem; padding: 0 1.25rem 1.25rem; }
.grabber { display: none; }
.sheet-bar {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: .5rem;
  padding: .75rem 0 .25rem; background: var(--surface);
}
.sheet-bar h2 { font-size: 1.0625rem; text-align: center; white-space: nowrap; }
.sheet-bar > :first-child { justify-self: start; margin-left: -.625rem; }
.sheet-bar > :last-child { justify-self: end; margin-right: -.625rem; }
.sheet-foot { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.sheet-foot .spacer { flex: 1; }

.amount-field { display: flex; align-items: baseline; justify-content: center; gap: .375rem; padding: .5rem 0 .75rem; border-bottom: 2px solid var(--separator); }
.amount-field:focus-within { border-color: var(--accent); }
.amount-field input {
  border: 0; background: none; min-height: 0; padding: 0; text-align: right; outline: none; border-radius: 0;
  font-family: var(--display); font-size: 2.5rem; font-weight: 700; letter-spacing: -.02em; width: 100%; max-width: 16rem;
  font-variant-numeric: tabular-nums;
}
.amount-field span { font-size: 1.75rem; font-weight: 600; color: var(--muted); }
.sheet[data-kind="income"] .amount-field input { color: var(--income); }
.sheet[data-kind="expense"] .amount-field input { color: var(--expense); }
.sheet .segmented { display: grid; }

.alert { width: min(18.5rem, calc(100vw - 3rem)); border-radius: 1rem; text-align: center; overflow: hidden; }
.alert[open] { animation: fade .15s ease; }
.alert .alert-body { padding: 1.25rem 1rem 1rem; }
.alert h2 { font-size: 1.0625rem; }
.alert p { font-size: .875rem; margin-top: .375rem; }
.alert .alert-buttons { display: grid; grid-template-columns: 1fr 1fr; border-top: 1px solid var(--separator); }
.alert .alert-buttons button {
  min-height: 2.75rem; border: 0; background: none; font: inherit; font-size: 1.0625rem; color: var(--accent); cursor: pointer;
}
.alert .alert-buttons button + button { border-left: 1px solid var(--separator); }
.alert .alert-buttons .destructive { color: var(--expense); font-weight: 600; }
.alert .alert-buttons button:hover { background: var(--surface-2); }

/* --- Meldungen ----------------------------------------------------------- */
.toasts { position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: .5rem; align-items: center; width: max-content; max-width: calc(100vw - 2rem); }
.toast {
  display: flex; align-items: center; gap: .5rem; background: var(--text); color: var(--bg);
  padding: .375rem 1rem; min-height: 2.75rem; border-radius: 999px; font-size: .9375rem; font-weight: 550; box-shadow: var(--shadow);
  animation: fade .2s ease;
}
.toast.err { background: var(--expense); color: #fff; }
.toast button {
  border: 0; background: transparent; color: inherit; font: inherit; font-weight: 700; margin-right: -.5rem;
  padding: 0 .75rem; min-height: 2.25rem; border-radius: 999px; cursor: pointer; text-decoration: underline; text-underline-offset: 3px;
}

.fab { display: none; }

/* --- Anpassung an Breite ------------------------------------------------- */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2-1 { grid-template-columns: 1fr; }
  .donut-wrap { flex-direction: row; align-items: center; }
}

/* Telefon: Tabbar unten aus Glas, großer Titel, Blätter von unten */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: auto; z-index: 20;
    padding: .25rem .5rem max(.5rem, env(safe-area-inset-bottom)); border: 0; border-top: 1px solid var(--separator);
    background: var(--glass); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  }
  .sidebar .brand, .sidebar-foot { display: none; }
  .nav { flex-direction: row; justify-content: space-around; }
  .nav a { flex: 1; flex-direction: column; justify-content: center; gap: .125rem; min-height: 3.125rem; padding: .25rem 0; font-size: .75rem; color: var(--muted); font-weight: 500; }
  .nav a svg { color: inherit; width: 1.5rem; height: 1.5rem; }
  .nav a:hover { background: none; }
  .nav a[aria-current="page"] { background: none; color: var(--accent); font-weight: 600; }
  .nav a[aria-current="page"] svg { fill: var(--accent-soft); }

  .main { padding: max(.75rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) calc(6.5rem + env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left)); }
  .topbar { margin-bottom: 1rem; }
  .topbar h1 { font-size: 2.125rem; }
  #add-btn { display: none; }
  .fab {
    display: grid; place-items: center; position: fixed; right: max(1rem, env(safe-area-inset-right));
    bottom: calc(4.75rem + env(safe-area-inset-bottom)); width: 3.5rem; height: 3.5rem; border-radius: 50%;
    border: 0; background: var(--accent); color: var(--on-accent); cursor: pointer; z-index: 21;
    box-shadow: 0 6px 18px rgba(0, 0, 0, .25);
  }
  .fab svg { width: 1.625rem; height: 1.625rem; stroke-width: 2.5; }
  .grid-1-1 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; }
  .donut-wrap { flex-direction: column; }
  .toasts { bottom: calc(9.25rem + env(safe-area-inset-bottom)); }

  .sheet {
    width: 100vw; max-width: none; margin: auto 0 0; border-radius: 1.25rem 1.25rem 0 0;
    max-height: calc(100dvh - max(2.5rem, env(safe-area-inset-top)));
    padding-bottom: env(safe-area-inset-bottom);
  }
  .sheet[open] { animation: slide .3s cubic-bezier(.2, .8, .2, 1); }
  @keyframes slide { from { transform: translateY(100%); } to { transform: none; } }
  .grabber {
    display: block; width: 2.25rem; height: .3125rem; border-radius: 99px; background: var(--separator);
    margin: .375rem auto 0; border: 0; padding: 0; cursor: grab;
  }
  .grabber::after { content: ""; display: block; margin: -.75rem -2rem; height: 1.75rem; }
  .sheet-bar { padding-top: .25rem; }
}

@media (max-width: 520px) {
  .kpis { gap: .75rem; }
  .kpi { padding: 1rem; }
  .kpi-value { font-size: 1.375rem; }
  .topbar-actions, .month-switch { width: 100%; }
  .month-switch { justify-content: space-between; background: var(--surface); border-radius: 999px; box-shadow: var(--shadow); }
  .month-label { flex: 1; min-width: 0; }
  .field-row { flex-direction: column; }
  .card { padding: 1rem; }
  .toolbar .segmented { flex: 1 1 100%; }
  .count-word { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}

/* --- Systemeinstellungen ------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (prefers-reduced-transparency: reduce) {
  .sidebar { background: var(--surface) !important; -webkit-backdrop-filter: none !important; backdrop-filter: none !important; }
}
@media (forced-colors: active) {
  .chart .bar-inc, .chart .bar-exp { fill: CanvasText; }
  .btn, .segmented [aria-pressed="true"] { border: 1px solid ButtonText; }
}
