/* Cash – Stylesheet (Mobile First, ohne Framework)
   Aufbau: 1 Tokens · 2 Basis · 3 Layout · 4 Komponenten · 5 Tabellen · 6 Formulare · 7 Utilities */

/* 1 ── Tokens ─────────────────────────────────────────────── */
:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f0f3f5;
  --border: #dde3e8;
  --text: #17222b;
  --text-muted: #5d6b77;
  --primary: #1f4e5f;
  --primary-contrast: #ffffff;
  --primary-soft: #e3eef2;
  --income: #1d7a46;
  --expense: #b3372b;
  --budget: #2f5d9a;
  --actual: #7a4fb0;
  --forecast: #9a6a12;
  --ok: #1d7a46;
  --warn: #9a6a12;
  --error: #b3372b;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgb(16 24 32 / 6%), 0 2px 8px rgb(16 24 32 / 4%);
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --topbar-h: 3.25rem;
  --tabbar-h: 3.75rem;
  --sidenav-w: 14rem;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1519;
    --surface: #172026;
    --surface-2: #1d2830;
    --border: #2a3842;
    --text: #e6edf2;
    --text-muted: #9aaab6;
    --primary: #5fa8c0;
    --primary-contrast: #0f1519;
    --primary-soft: #1d3540;
    --income: #4cc17f;
    --expense: #ee7b6f;
    --budget: #7fa8e6;
    --actual: #b99be6;
    --forecast: #e0b056;
    --ok: #4cc17f;
    --warn: #e0b056;
    --error: #ee7b6f;
    --shadow: none;
  }
}

/* 2 ── Basis ──────────────────────────────────────────────── */
*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 var(--space-2); }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.125rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 var(--space-3); }
a { color: var(--primary); }
code { font-family: var(--font-mono); font-size: 0.875em; }

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

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--surface);
  padding: var(--space-2) var(--space-3);
  z-index: 100;
}
.skip-link:focus { left: var(--space-2); }

/* 3 ── Layout ─────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  height: var(--topbar-h);
  padding: 0 var(--space-4);
  padding-top: env(safe-area-inset-top);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text);
  text-decoration: none;
  font-weight: 650;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 7px;
  background: var(--primary);
  color: var(--primary-contrast);
  font-weight: 700;
}

.topbar-meta { display: flex; align-items: center; gap: var(--space-2); min-width: 0; }

.shell { display: block; }

.content {
  width: 100%;
  max-width: 80rem;
  margin: 0 auto;
  padding: var(--space-4);
  /* Platz für die Tab-Leiste auf dem Smartphone */
  padding-bottom: calc(var(--tabbar-h) + var(--space-5) + env(safe-area-inset-bottom));
}
.content:focus { outline: none; }

.sidenav { display: none; }

.tabbar {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 20;
  display: flex;
  justify-content: space-around;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 3rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.75rem;
}
.tab.is-active { color: var(--primary); font-weight: 600; }

.tab-icon {
  width: 1.4rem;
  height: 1.4rem;
  background: currentColor;
  -webkit-mask: var(--icon) center / contain no-repeat;
  mask: var(--icon) center / contain no-repeat;
}
.icon-home { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 3 2 11h3v9h6v-6h2v6h6v-9h3z'/%3E%3C/svg%3E"); }
.icon-layers { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='m12 2 10 5-10 5L2 7zm-7.6 8.8L12 14.6l7.6-3.8L22 12l-10 5-10-5zm0 5L12 19.6l7.6-3.8L22 17l-10 5-10-5z'/%3E%3C/svg%3E"); }
.icon-shield { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2 4 5v6c0 5 3.4 9.7 8 11 4.6-1.3 8-6 8-11V5z'/%3E%3C/svg%3E"); }
.icon-gear { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M19.4 13a7.6 7.6 0 0 0 0-2l2.1-1.6-2-3.5-2.5 1a7.4 7.4 0 0 0-1.7-1L15 3h-4l-.4 2.9a7.4 7.4 0 0 0-1.7 1l-2.5-1-2 3.5L6.6 11a7.6 7.6 0 0 0 0 2l-2.1 1.6 2 3.5 2.5-1a7.4 7.4 0 0 0 1.7 1L11 21h4l.4-2.9a7.4 7.4 0 0 0 1.7-1l2.5 1 2-3.5zM13 15.5a3.5 3.5 0 1 1 0-7 3.5 3.5 0 0 1 0 7z'/%3E%3C/svg%3E"); }

.icon-budget { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 5h18v3H3zm0 5h18v9H3zm12 3v3h4v-3z'/%3E%3C/svg%3E"); }
.icon-tag { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 3h8l10 10-8 8L3 11zm4.5 6A1.5 1.5 0 1 0 7.5 6a1.5 1.5 0 0 0 0 3z'/%3E%3C/svg%3E"); }

.icon-list { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 5h2v2H3zm4 0h14v2H7zM3 11h2v2H3zm4 0h14v2H7zm-4 6h2v2H3zm4 0h14v2H7z'/%3E%3C/svg%3E"); }

.icon-chart { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 3h2v16h16v2H3zm4 10h3v5H7zm5-6h3v11h-3zm5 3h3v8h-3z'/%3E%3C/svg%3E"); }

.nav-icon {
  display: inline-block;
  width: 1.1rem;
  height: 1.1rem;
  margin-right: var(--space-2);
  vertical-align: -0.2rem;
  background: currentColor;
  -webkit-mask: var(--icon) center / contain no-repeat;
  mask: var(--icon) center / contain no-repeat;
}

.shell-plain .content { padding-bottom: var(--space-6); }

.tenant-chip {
  max-width: 11rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0.2rem 0.7rem;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
  font-size: 0.875rem;
  text-decoration: none;
}
.user-name { display: none; font-size: 0.875rem; }
/* Smartphone: Platz in der Kopfzeile für Mandant und Abmelden */
@media (max-width: 30rem) {
  .topbar:has(.topbar-meta) .brand-name { display: none; }
}
@media (min-width: 40rem) { .user-name { display: inline; } }
.inline-form { margin: 0; }

@media (min-width: 60rem) {
  .shell {
    display: grid;
    grid-template-columns: var(--sidenav-w) minmax(0, 1fr);
  }

  .sidenav {
    display: block;
    position: sticky;
    top: var(--topbar-h);
    height: calc(100vh - var(--topbar-h));
    padding: var(--space-4) var(--space-3);
    border-right: 1px solid var(--border);
    background: var(--surface);
  }
  .sidenav ul { list-style: none; margin: 0; padding: 0; }

  .nav-link {
    display: block;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    color: var(--text);
    text-decoration: none;
  }
  .nav-link:hover { background: var(--surface-2); }
  .nav-link.is-active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }

  .tabbar { display: none; }
  .content { padding: var(--space-5) var(--space-6); }
  .shell-plain { display: block; }
}

/* 4 ── Komponenten ────────────────────────────────────────── */
.page-header { margin-bottom: var(--space-5); }

.grid {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: minmax(0, 1fr);
}
@media (min-width: 40rem) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(18rem, 1fr)); }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--space-4);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}
.card-header h2 { margin: 0; }

.kv {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--space-2) var(--space-4);
  margin: 0;
}
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; text-align: right; }

.status-list { list-style: none; margin: 0 0 var(--space-3); padding: 0; }
.status-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border);
}
.status-list li:last-child { border-bottom: 0; }

.badge {
  display: inline-block;
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid currentColor;
  white-space: nowrap;
}
.badge-ok { color: var(--ok); }
.badge-pending { color: var(--warn); }
.badge-error { color: var(--error); }
.badge-info { color: var(--budget); }
/* Wertarten der Jahresübersicht – immer eindeutig gekennzeichnet */
.badge-budget { color: var(--budget); }
.badge-actual { color: var(--actual); }
.badge-forecast { color: var(--forecast); }

.hint {
  padding: var(--space-2) var(--space-3);
  border-left: 3px solid var(--warn);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 2.75rem; /* touchfreundlich */
  padding: 0 var(--space-4);
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: var(--primary-contrast);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; color: var(--primary); }
.btn-sm { min-height: 2.25rem; padding: 0 var(--space-3); font-size: 0.875rem; }
.btn-danger { background: var(--expense); border-color: var(--expense); }

/* htmx: Ladeanzeige (Indikator-Styles von htmx sind wegen CSP deaktiviert) */
.htmx-indicator { opacity: 0; transition: opacity 150ms ease-in; }
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { opacity: 1; }

.spinner {
  width: 0.9rem;
  height: 0.9rem;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.section { margin-top: var(--space-6); }
.mt { margin-top: var(--space-5); }

.breadcrumb { font-size: 0.875rem; color: var(--text-muted); margin-bottom: var(--space-2); }
.breadcrumb a { color: inherit; }

.flash {
  margin-bottom: var(--space-4);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  border-left: 4px solid var(--ok);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.flash-warn { border-left-color: var(--warn); }
.flash-info { border-left-color: var(--budget); }

.card-link { display: block; color: inherit; text-decoration: none; }
.card-link:hover { border-color: var(--primary); }
.card-link h2 { color: var(--primary); }

.layout-2 { display: grid; gap: var(--space-5); align-items: start; }
@media (min-width: 60rem) { .layout-2 { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); } }

.row-list,
.plain-list,
.toggle-list,
.tile-list { list-style: none; margin: 0; padding: 0; }

.row-list { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.row-list li + li { border-top: 1px solid var(--border); }
.row-link {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-1) var(--space-3);
  min-height: 3.25rem;
  padding: var(--space-3) var(--space-4);
  color: inherit;
  text-decoration: none;
}
.row-link:hover { background: var(--surface-2); }
.row-link .badge { margin-left: var(--space-1); }

.plain-list li { padding: var(--space-1) 0; }

.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border);
}
.toggle-row:last-child { border-bottom: 0; }
.toggle-row form { margin: 0; flex-shrink: 0; }

.tile-list { display: grid; gap: var(--space-3); grid-template-columns: minmax(0, 1fr); }
@media (min-width: 40rem) { .tile-list { grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr)); } }
.tile-list form { margin: 0; }
.tile {
  display: flex;
  width: 100%;
  min-height: 4.5rem;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.tile:hover,
.tile.is-active { border-color: var(--primary); }
.tile-title { font-weight: 650; font-size: 1.05rem; }

/* Anmeldung */
.page-auth .content { max-width: 30rem; padding-top: var(--space-6); }
.auth-card { padding: var(--space-5); }
.auth-card-wide { max-width: 34rem; margin: 0 auto; }
.page-auth .content:has(.auth-card-wide) { max-width: 36rem; }
.auth-alt { margin: var(--space-4) 0 0; text-align: center; font-size: 0.9rem; }
.qr { display: flex; justify-content: center; margin: var(--space-4) 0; }
.qr svg { display: block; width: 14rem; max-width: 100%; height: auto; aspect-ratio: 1 / 1; border-radius: var(--radius-sm); }
.manual-secret { margin-bottom: var(--space-4); }
.manual-secret summary { cursor: pointer; color: var(--primary); }
.secret { font-size: 1rem; word-spacing: 0.3rem; user-select: all; }
.codes {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-2) var(--space-4);
  margin: var(--space-4) 0 var(--space-5);
  padding-left: 1.5rem;
  font-size: 1.05rem;
}
.input-code { font-family: var(--font-mono); letter-spacing: 0.15em; font-size: 1.25rem; }

/* Seitenkopf mit Aktionen */
.page-header-row { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--space-3); }
.year-switch { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.grid-wide { grid-template-columns: minmax(0, 1fr); }
@media (min-width: 60rem) { .grid-wide { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* Kennzahlen */
.summary-grid { display: grid; gap: var(--space-3); grid-template-columns: minmax(0, 1fr); margin-bottom: var(--space-5); }
@media (min-width: 40rem) { .summary-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.stat {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.stat-label { color: var(--text-muted); font-size: 0.875rem; display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }
.stat-value { font-size: 1.5rem; font-weight: 650; text-align: left; }
.stat-sub { color: var(--text-muted); font-size: 0.8rem; text-align: left; white-space: normal; }
.stat-highlight { border-color: var(--primary); }

.tile-stack { flex-direction: column; align-items: stretch; }
.kv-compact { gap: var(--space-1) var(--space-3); font-size: 0.9rem; }

/* Jahresbudget */
.budget-section { margin-bottom: var(--space-6); }
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  padding-bottom: var(--space-2);
  margin-bottom: var(--space-3);
  border-bottom: 2px solid var(--border);
}
.section-head h2 { margin: 0; }
.section-total { font-weight: 650; }
.cat-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: var(--space-3);
  overflow: hidden;
}
.cat-head, .subcat-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
}
.cat-head { background: var(--surface-2); }
.cat-head h3, .subcat-head h4 { margin: 0; font-size: 1rem; }
.subcat-head { padding-top: var(--space-3); padding-bottom: var(--space-1); }
.subcat-head h4 { font-size: 0.9rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.subcat + .subcat, .item-list + .subcat { border-top: 1px solid var(--border); }
.is-inactive > .cat-head, .is-inactive > .subcat-head { opacity: 0.7; }

.item-list { list-style: none; margin: 0; padding: 0; }
.item-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--space-1) var(--space-3);
  align-items: center;
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border);
}
.item-list > li:first-child { border-top: 0; }
.item-main { display: flex; flex-direction: column; min-width: 0; }
.item-name { font-weight: 600; }
.item-meta { color: var(--text-muted); font-size: 0.82rem; }
.item-total { font-weight: 600; }
.item-actions { grid-column: 1 / -1; display: flex; gap: var(--space-2); justify-content: flex-end; }
@media (min-width: 48rem) {
  .item-row { grid-template-columns: minmax(0, 1fr) 9rem auto; }
  .item-actions { grid-column: auto; }
}
.item-row.is-inactive .item-name, .item-row.is-inactive .item-total { color: var(--text-muted); text-decoration: line-through; }
.item-row.is-carry { background: var(--surface-2); }
.item-row.is-carry .item-name::before { content: "↪ "; color: var(--text-muted); }
.add-item { padding: var(--space-2) var(--space-4) var(--space-3); }

/* Aktionsmenü (ohne JavaScript, <details>) */
.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-panel {
  position: absolute;
  right: 0;
  z-index: 10;
  min-width: 12rem;
  margin-top: var(--space-1);
  padding: var(--space-1);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 6px 24px rgb(16 24 32 / 15%);
}
.menu-panel form { margin: 0; }
.menu-item {
  display: block;
  width: 100%;
  min-height: 2.5rem;
  padding: var(--space-2) var(--space-3);
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.menu-item:hover { background: var(--surface-2); }
.menu-danger { color: var(--expense); }

/* Formulare für Positionen */
.item-form-wrap { display: block; padding: var(--space-4); border-top: 1px solid var(--border); background: var(--surface); }
.form-grid { display: grid; gap: var(--space-3); grid-template-columns: minmax(0, 1fr); }
@media (min-width: 40rem) {
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span-2 { grid-column: span 2; }
}
.form-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-4); }
.segmented { border: 0; padding: 0; margin: 0; display: flex; gap: var(--space-2); flex-wrap: wrap; }
.segmented legend { font-weight: 600; margin-bottom: var(--space-1); padding: 0; }
.segmented label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 2.75rem;
  padding: 0 var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-weight: 400;
  cursor: pointer;
}
.segmented label:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.segmented input { width: auto; min-height: 0; }
/* Felder je nach Rhythmus ein-/ausblenden (reines CSS) */
.item-form:has(input[value="monthly"]:checked) .yearly-fields,
.item-form:has(input[value="monthly"]:checked) .yearly-fields-hint,
.item-form:has(input[value="monthly"]:checked) .when-yearly,
.item-form:has(input[value="yearly"]:checked) .when-monthly { display: none; }
.input-amount { text-align: right; font-variant-numeric: tabular-nums; }
.field-error { margin: var(--space-1) 0 0; color: var(--error); font-size: 0.85rem; }
[aria-invalid="true"] { border-color: var(--error); box-shadow: 0 0 0 1px var(--error); }

.months-grid { display: grid; gap: var(--space-2); grid-template-columns: repeat(3, minmax(0, 1fr)); margin-top: var(--space-3); }
@media (min-width: 40rem) { .months-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
.month-field label { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 2px; }
.month-field.is-override input { border-color: var(--forecast); background: color-mix(in srgb, var(--forecast) 8%, var(--surface)); }

/* Kategorien */
.kind-title { margin-bottom: var(--space-3); }
.cat-tree, .cat-children { list-style: none; margin: 0; padding: 0; }
.cat-children { padding-left: var(--space-4); border-left: 2px solid var(--border); margin: var(--space-1) 0 var(--space-3) var(--space-2); }
.cat-line { display: flex; justify-content: space-between; align-items: center; gap: var(--space-2); min-height: 2.75rem; }
.cat-tree > .cat-node > .cat-line .cat-name { font-weight: 650; }
.cat-node.is-inactive > .cat-line .cat-name { color: var(--text-muted); }
.add-sub { margin: var(--space-1) 0; }
.add-sub > summary { list-style: none; display: inline-flex; }
.add-sub > summary::-webkit-details-marker { display: none; }
.add-sub[open] > summary { display: none; }
.inline-add { display: flex; gap: var(--space-2); align-items: center; margin: var(--space-2) 0; }
.inline-add input[type="text"] { flex: 1; min-width: 0; }

/* Transaktionen */
.tx-new { margin-bottom: var(--space-4); }
.tx-new h2 { margin-bottom: var(--space-3); }
.tx-form-wrap { display: block; }
.tx-row .tx-form-wrap, li.tx-form-wrap { padding: var(--space-4); background: var(--surface); }
.tx-types { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin-bottom: var(--space-3); }
.tx-types label { justify-content: center; padding: 0 var(--space-2); font-size: 0.9rem; text-align: center; }
@media (min-width: 40rem) { .tx-types label { font-size: 1rem; } }
.tx-types .type-expense:has(input:checked) { border-color: var(--expense); color: var(--expense); background: color-mix(in srgb, var(--expense) 8%, var(--surface)); }
.tx-types .type-income:has(input:checked) { border-color: var(--income); color: var(--income); background: color-mix(in srgb, var(--income) 8%, var(--surface)); }
.tx-grid { display: grid; gap: var(--space-3); grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.tx-desc, .tx-cat { grid-column: 1 / -1; }
.tx-amount .input-amount { font-size: 1.25rem; font-weight: 600; }
@media (min-width: 60rem) {
  .tx-grid { grid-template-columns: 9rem 10rem minmax(0, 2fr) minmax(0, 2fr); }
  .tx-desc, .tx-cat { grid-column: auto; }
}

.filter-bar { display: grid; gap: var(--space-2); grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); margin-bottom: var(--space-4); }
.filter-search { grid-column: 1 / -1; }
@media (min-width: 60rem) {
  .filter-bar { grid-template-columns: minmax(0, 2fr) repeat(3, minmax(0, 1fr)); }
  .filter-search { grid-column: auto; }
}

.tx-list {
  list-style: none;
  margin: 0 0 var(--space-4);
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.tx-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "main amount" "date actions";
  gap: var(--space-1) var(--space-3);
  align-items: center;
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border);
}
.tx-list > li:first-child { border-top: 0; }
.tx-date-col { grid-area: date; text-align: left; color: var(--text-muted); font-size: 0.85rem; }
.tx-main { grid-area: main; display: flex; flex-direction: column; min-width: 0; }
.tx-desc-text { font-weight: 600; overflow-wrap: anywhere; }
.tx-meta { color: var(--text-muted); font-size: 0.82rem; }
.tx-amount-col { grid-area: amount; font-weight: 650; font-size: 1.05rem; }
.tx-actions { grid-area: actions; display: flex; gap: var(--space-1); justify-content: flex-end; }
.tx-actions form { margin: 0; }
.btn-icon { min-width: 2.25rem; padding: 0 var(--space-2); }
@media (min-width: 48rem) {
  .tx-row { grid-template-columns: 6.5rem minmax(0, 1fr) 9rem auto; grid-template-areas: "date main amount actions"; }
  .tx-date-col { font-size: 0.9rem; color: var(--text); }
}
.tx-row.is-editing, .tx-list > .tx-form-wrap { border-top: 1px solid var(--border); }
.empty { color: var(--text-muted); margin-bottom: var(--space-4); }
.table-compact th, .table-compact td { padding: var(--space-1) var(--space-2); }
.table-compact tfoot th { border-bottom: 0; }
.table-compact a { color: inherit; }

/* Jahresübersicht */
.figure-grid { display: grid; gap: var(--space-3); grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: var(--space-3); }
@media (min-width: 60rem) { .figure-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 80rem) { .figure-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
.figure-grid .stat-value { font-size: 1.2rem; }
.stat .stat-sub { white-space: normal; text-align: left; }
.legend { font-size: 0.85rem; color: var(--text-muted); margin-bottom: var(--space-4); }
.hint-block { margin-bottom: var(--space-4); }
.overview-controls { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; justify-content: space-between; margin-bottom: var(--space-3); }
.segmented-links { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); }
.segmented-links a { padding: var(--space-2) var(--space-3); min-height: 2.5rem; display: inline-flex; align-items: center; color: var(--text); text-decoration: none; font-size: 0.9rem; }
.segmented-links a + a { border-left: 1px solid var(--border); }
.segmented-links a.is-active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }

.overview-desktop { display: none; }
.overview-scroll { max-height: calc(100vh - var(--topbar-h) - 3rem); overflow: auto; }
@media (min-width: 60rem) {
  .overview-desktop { display: block; }
  .overview-mobile { display: none; }
}
.overview-table { font-size: 0.85rem; min-width: 72rem; }
.overview-table th, .overview-table td { padding: 0.35rem 0.55rem; white-space: nowrap; }
.overview-table thead a { color: inherit; text-decoration: none; }
.overview-table thead a:hover { text-decoration: underline; }
.overview-table .sticky-col { min-width: 15rem; max-width: 20rem; overflow: hidden; text-overflow: ellipsis; text-align: left; font-weight: 400; }
.overview-table .section-row th, .overview-table .section-row td { background: var(--surface-2); font-weight: 650; padding-top: var(--space-3); }
.overview-table .lvl-0 th { font-weight: 650; }
.overview-table .lvl-1 th { padding-left: 1.2rem; }
.overview-table .lvl-2 th { padding-left: 2.1rem; color: var(--text-muted); }
.overview-table .lvl-3 th { padding-left: 3rem; color: var(--text-muted); font-size: 0.8rem; }
.overview-table .is-emphasis td, .overview-table .is-emphasis th { font-weight: 650; }
.overview-table .col-year { font-weight: 650; background: var(--surface-2); position: sticky; right: 0; }
.overview-table .is-current { background: color-mix(in srgb, var(--primary) 7%, var(--surface)); }
.overview-table td a { color: var(--actual); text-decoration: none; border-bottom: 1px dotted currentColor; }
.overview-table td a:hover { border-bottom-style: solid; }
.zero { color: var(--border); }
.is-negative { color: var(--expense); }
.row-note { color: var(--text-muted); font-size: 0.75rem; margin-left: var(--space-1); }
.vt-forecast .is-emphasis th, .vt-forecast .is-emphasis td { background: color-mix(in srgb, var(--forecast) 8%, var(--surface)); }

.month-chips { display: flex; gap: var(--space-1); overflow-x: auto; padding-bottom: var(--space-2); margin-bottom: var(--space-2); scrollbar-width: thin; }
.chip { flex: 0 0 auto; min-width: 3rem; min-height: 2.5rem; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--text); text-decoration: none; font-size: 0.9rem; }
.chip.is-current { border-color: var(--primary); }
.chip.is-active { background: var(--primary); border-color: var(--primary); color: var(--primary-contrast); font-weight: 600; }
.mobile-month-title { margin: var(--space-2) 0 var(--space-3); }
.mobile-section { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: var(--space-3); overflow: hidden; }
.mobile-section h3 { margin: 0; padding: var(--space-3) var(--space-4); background: var(--surface-2); font-size: 0.95rem; display: flex; gap: var(--space-2); align-items: center; }
.mobile-rows { list-style: none; margin: 0; padding: 0; }
.mobile-rows li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0 var(--space-3); padding: var(--space-2) var(--space-4); border-top: 1px solid var(--border); }
.mobile-rows li:first-child { border-top: 0; }
.mr-label { min-width: 0; overflow-wrap: anywhere; }
.mr-value { font-weight: 600; }
.mr-value a { color: var(--actual); }
.mr-year { grid-column: 1 / -1; font-size: 0.75rem; text-align: left; }
.mobile-rows .lvl-0 .mr-label, .mobile-rows .is-emphasis .mr-label { font-weight: 650; }
.mobile-rows .lvl-1 .mr-label { padding-left: var(--space-2); }
.mobile-rows .lvl-2 .mr-label, .mobile-rows .lvl-3 .mr-label { padding-left: var(--space-4); color: var(--text-muted); }

/* 5 ── Tabellen ───────────────────────────────────────────── */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 0.9rem; }
.table th,
.table td { padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--border); }
.table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface-2);
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
}
/* erste Spalte bleibt beim horizontalen Scrollen sichtbar */
.table .sticky-col {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--surface);
}
.table thead .sticky-col { z-index: 3; background: var(--surface-2); }

/* 6 ── Formulare ──────────────────────────────────────────── */
label { display: block; font-weight: 600; margin-bottom: var(--space-1); }

input,
select,
textarea {
  width: 100%;
  min-height: 2.75rem;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 1rem; /* verhindert Auto-Zoom auf iOS */
}

.stack { display: grid; gap: var(--space-4); }
.stack > * { margin: 0; }
.field-hint { margin: var(--space-1) 0 0; font-size: 0.85rem; color: var(--text-muted); }
.form-error {
  padding: var(--space-2) var(--space-3);
  border-left: 3px solid var(--error);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  color: var(--error);
}
.checkbox { display: flex; align-items: center; gap: var(--space-2); font-weight: 400; min-height: 2.75rem; cursor: pointer; }
.checkbox input { width: 1.25rem; min-height: 1.25rem; height: 1.25rem; margin: 0; }
.btn-block { width: 100%; }
button:disabled { opacity: 0.6; cursor: not-allowed; }

/* 7 ── Utilities ──────────────────────────────────────────── */
.muted { color: var(--text-muted); }
.small { font-size: 0.85rem; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.amount-income { color: var(--income); }
.amount-expense { color: var(--expense); }
.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
