/* ─── Design-System ───────────────────────────────────────────────────────── */
:root, [data-theme="gruen"] {
    --bg:          #f0f2f5;
    --surface:     #ffffff;
    --surface-2:   #f7f8fa;
    --border:      #dde1e8;
    --border-dark: #c5cad4;
    --text-primary:   #1a1d23;
    --text-secondary: #5a6275;
    --text-muted:     #8a90a0;
    --accent:      #059669;
    --accent-dark: #047857;
    --accent-soft: #ecfdf5;
    --accent-border: var(--accent-border);
    --accent-tint: #d1fae5;
    --on-accent:   #ffffff;
    --focus:       rgba(5,150,105,.18);
    --header-bg:   #064e3b;
    --header-text: #ffffff;
    --positive:    #047857;
    --green:       #16a34a;
    --red:         #dc2626;
    --red-bg:      #fef2f2;
    --red-border:  #f5c6cb;
    --red-hover:   #f8d7da;
    --amber:       #d97706;
    --warn-bg:     #fffbeb;
    --warn-border: #fcd34d;
    --info-bg:     #eff6ff;
    --info-border: #93c5fd;
    --overlay:     rgba(0,0,0,.45);
    --toast-bg:    #1a1d23;
    --header-h:    54px;
    --radius:      8px;
    --radius-sm:   6px;
    --shadow:      0 1px 3px rgba(0,0,0,.08);
    --shadow-md:   0 4px 16px rgba(0,0,0,.12);
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
    color-scheme: light;
}

/* ─── Designs (Einstellungen → Design) ───────────────────────────────────── */
[data-theme="blau"] {
    --bg: #f1f5f9; --border: #dbe2ea; --border-dark: #c3ccd8;
    --accent: #2563eb; --accent-dark: #1d4ed8; --accent-soft: #eff6ff; --accent-border: #bfdbfe; --accent-tint: #dbeafe;
    --focus: rgba(37,99,235,.18); --header-bg: #1e3a8a; --positive: #047857;
}
[data-theme="sand"] {
    --bg: #f4efe6; --surface: #fffdf9; --surface-2: #faf5ec; --border: #e8dfd0; --border-dark: #d5c8b4;
    --text-primary: #292524; --text-secondary: #57534e; --text-muted: #948b82;
    --accent: #b45309; --accent-dark: #92400e; --accent-soft: #fdf4e7; --accent-border: #f1d6ad; --accent-tint: #fae6c8;
    --focus: rgba(180,83,9,.18); --header-bg: #44403c; --positive: #3f7d3a;
}
[data-theme="dunkel"] {
    --bg: #0f172a; --surface: #1e293b; --surface-2: #172033; --border: #334155; --border-dark: #475569;
    --text-primary: #e2e8f0; --text-secondary: #a3b0c2; --text-muted: #718096;
    --accent: #34d399; --accent-dark: #10b981; --accent-soft: rgba(52,211,153,.12); --accent-border: rgba(52,211,153,.35);
    --accent-tint: rgba(52,211,153,.16); --on-accent: #052e1f; --focus: rgba(52,211,153,.25);
    --header-bg: #020617; --header-text: #e2e8f0; --positive: #34d399; --green: #22c55e;
    --red: #f87171; --red-bg: rgba(248,113,113,.12); --red-border: rgba(248,113,113,.35); --red-hover: rgba(248,113,113,.22);
    --amber: #fbbf24; --warn-bg: rgba(251,191,36,.10); --warn-border: rgba(251,191,36,.45);
    --info-bg: rgba(96,165,250,.10); --info-border: rgba(96,165,250,.45);
    --overlay: rgba(0,0,0,.65); --toast-bg: #334155;
    --shadow: 0 1px 3px rgba(0,0,0,.4); --shadow-md: 0 4px 16px rgba(0,0,0,.5);
    color-scheme: dark;
}

/* Einfach-Modus: Expertenfunktionen ausblenden */
[data-mode="simple"] .expert-only { display: none !important; }

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--text-primary); font-size: 14px; line-height: 1.5; min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }

/* ── Header ── */
.header {
  background: var(--header-bg); color: var(--header-text); padding: 0 1rem; height: 54px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 100; box-shadow: 0 2px 8px rgba(0,0,0,.25);
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
}
.header-brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; font-size: 1.05rem; }
.header-brand svg { opacity: .9; }
.header-date { font-size: .85rem; opacity: .8; }

/* ── Shell ── */
.app-shell { display: flex; min-height: calc(100vh - 54px); }

/* ── Sidebar ── */
.sidebar {
  width: 220px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border);
  padding: 1.2rem .75rem; display: flex; flex-direction: column; gap: .15rem;
  position: sticky; top: 54px; height: calc(100vh - 54px); overflow-y: auto;
}
.sidebar-item {
  display: flex; align-items: center; gap: .6rem; padding: .55rem .75rem; border-radius: var(--radius-sm);
  border: none; background: none; width: 100%; color: var(--text-secondary); font-size: .88rem; font-weight: 500;
  cursor: pointer; transition: background .12s, color .12s; text-align: left; font-family: var(--font);
}
.sidebar-item:hover { background: var(--surface-2); color: var(--text-primary); }
.sidebar-item.active { background: var(--accent-soft); color: var(--accent); }
.sidebar-item svg { width: 18px; height: 18px; flex-shrink: 0; }

/* ── Main Content ── */
.main-content { flex: 1; overflow-x: hidden; padding: 1.2rem 1rem; max-width: 1100px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
@media (max-width: 640px) { .grid-2 { grid-template-columns: 1fr; } }

/* ── Bottom Nav ── */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface);
  border-top: 1px solid var(--border); display: flex; z-index: 99;
  box-shadow: 0 -2px 8px rgba(0,0,0,.08);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: .45rem .2rem .35rem; gap: .15rem; border: none; background: none;
  color: var(--text-muted); font-size: .62rem; font-weight: 500; transition: color .12s; font-family: var(--font); cursor: pointer;
}
.nav-item.active { color: var(--accent); }
.nav-item svg { width: 20px; height: 20px; }

@media (min-width: 768px) {
  .bottom-nav { display: none; }
}
@media (max-width: 767px) {
  .sidebar { display: none; }
  .main-content { padding-bottom: 70px; padding-left: max(1rem, env(safe-area-inset-left)); padding-right: max(1rem, env(safe-area-inset-right)); }
}

/* Toast */
.toast {
    position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
    background: var(--toast-bg); color: #fff; padding: 10px 20px; border-radius: 99px;
    font-size: 13px; font-weight: 500; z-index: 9999; white-space: nowrap;
    animation: slideUp .2s ease; box-shadow: 0 4px 16px rgba(0,0,0,.2);
}
.toast.hidden { display: none; }
.toast.success { background: var(--green); }
.toast.error { background: var(--red); }
@keyframes slideUp { from { opacity:0; transform:translateX(-50%) translateY(12px); } to { opacity:1; transform:translateX(-50%) translateY(0); } }

/* Toolbar */
.toolbar { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; margin-bottom: 0; padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0; }
.toolbar-group { display: flex; flex-direction: column; gap: 4px; }
.toolbar-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); }
.toolbar-spacer { flex: 1; }
.toolbar-divider { width: 1px; height: 36px; background: var(--border); align-self: center; }

/* Stats Bar */
.stats-bar-outer { background: var(--surface); border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
.stats-bar { display: flex; gap: 1px; background: var(--border); }
.stat-item { flex: 1; background: var(--surface); padding: 10px 16px; display: flex; align-items: center; gap: 10px; }
.stat-label { font-size: 12px; color: var(--text-secondary); white-space: nowrap; }
.stat-value { font-size: 16px; font-weight: 700; color: var(--text-primary); letter-spacing: -.3px; font-variant-numeric: tabular-nums; }
.stat-value--accent { color: var(--accent); }
.stat-value--green  { color: var(--positive); }
.stat-value--red    { color: var(--text-primary); }

/* Table Container */
.table-container { background: var(--surface); border: 1px solid var(--border); border-top: none; border-radius: 0 0 var(--radius) var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.table-container--standalone { border-top: 1px solid var(--border); border-radius: var(--radius); margin-top: 14px; }

/* Data Table */
.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table thead th { background: var(--header-bg); color: var(--header-text); padding: 10px 14px; font-size: 12px; font-weight: 600; text-align: left; white-space: nowrap; border-right: 1px solid rgba(255,255,255,.12); user-select: none; }
.data-table thead th:last-child { border-right: none; }
.data-table thead th.th-right { text-align: right; }
.data-table tbody tr { border-bottom: 1px solid var(--border); transition: background .1s; }
.data-table tbody tr:last-child { border-bottom: none; }
.data-table tbody tr:nth-child(even) td { background: var(--surface-2); }
.data-table tbody tr:hover td { background: var(--accent-soft) !important; }
.data-table tbody td { padding: 9px 14px; vertical-align: middle; white-space: nowrap; }
.data-table tbody td.td-right { text-align: right; font-variant-numeric: tabular-nums; }

.td-date { color: var(--accent); font-weight: 600; cursor: pointer; }
.td-date:hover { color: var(--accent-dark); text-decoration: underline; }
.td-desc { max-width: 300px; overflow: hidden; text-overflow: ellipsis; }
.td-cat { color: var(--text-secondary); font-size: 13px; max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
.td-amount { font-weight: 700; }
.td-amount.expense { color: var(--text-primary); }
.td-amount.income  { color: var(--positive); }
.td-muted { color: var(--text-muted); }
.td-actions { display: flex; gap: 5px; }

/* Category Table */
.cat-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.cat-table thead th { background: var(--accent-tint); color: var(--accent-dark); padding: 8px 14px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; text-align: left; border-bottom: 1px solid var(--border); }
.cat-table thead th.th-right { text-align: right; }
.cat-table tbody tr { border-bottom: 1px solid var(--border); cursor: pointer; }
.cat-table tbody tr:last-child { border-bottom: none; }
.cat-table tbody tr:hover td { background: var(--accent-soft); }
.cat-table tbody td { padding: 8px 14px; vertical-align: middle; }
.cat-table .td-right { text-align: right; font-variant-numeric: tabular-nums; }
.cat-name { font-weight: 600; }
.cat-pct { font-size: 11px; color: var(--text-muted); }
.cat-amount { font-weight: 700; color: var(--text-primary); }

/* Subcategory rows */
.sub-row { display: none; }
.sub-row.visible { display: table-row; }
.sub-row td { padding: 5px 14px 5px 28px !important; font-size: 13px; color: var(--text-secondary); }
.sub-name { padding-left: 8px; }
.sub-amount { font-weight: 500; color: var(--text-primary); text-align: right; }

/* Category bar in table */
.cat-bar-cell { padding: 4px 0; }
.cat-bar { height: 5px; background: var(--border); border-radius: 99px; overflow: hidden; width: 100px; }
.cat-bar-fill { height: 100%; border-radius: 99px; background: var(--accent); transition: width .3s; }

/* Empty */
.empty-state { text-align: center; padding: 48px 16px; color: var(--text-secondary); }
.empty-icon { font-size: 32px; margin-bottom: 10px; }
.empty-text { font-size: 14px; margin-bottom: 14px; }
.empty-text small { font-size: 12px; color: var(--text-muted); }

/* Modal */
.modal-overlay { display: none; position: fixed; inset: 0; background: var(--overlay); z-index: 500; align-items: center; justify-content: center; padding: 16px; }
.modal-overlay.open { display: flex; }
.modal { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-md); width: 100%; max-width: 640px; overflow: hidden; animation: modalIn .18s ease-out; }
@keyframes modalIn { from { opacity:0; transform:scale(.97) translateY(-6px); } to { opacity:1; transform:scale(1) translateY(0); } }
.modal-header { background: var(--header-bg); color: var(--header-text); padding: 12px 18px; display: flex; align-items: center; justify-content: space-between; }
.modal-title { font-size: 14px; font-weight: 700; }
.modal-close { background: none; border: none; color: rgba(255,255,255,.8); font-size: 20px; cursor: pointer; line-height: 1; padding: 0 4px; font-family: var(--font); }
.modal-close:hover { color: #fff; }
.modal-body { padding: 18px; display: flex; flex-direction: column; gap: 13px; }
.modal-footer { padding: 11px 18px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; align-items: center; }
.modal-footer-left { margin-right: auto; display: flex; gap: 6px; }

/* Forms */
.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-label { font-size: 11px; font-weight: 700; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .4px; }
.optional { color: var(--text-muted); font-weight: 400; text-transform: none; letter-spacing: 0; }
.form-control { width: 100%; padding: 8px 10px; border: 1.5px solid var(--border-dark); border-radius: var(--radius-sm); font-size: 14px; font-family: var(--font); color: var(--text-primary); background: var(--surface); transition: border-color .12s, box-shadow .12s; -webkit-appearance: none; appearance: none; min-height: 36px; }
.form-control:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
select.form-control { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%235a6275' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; }
.form-control--lg { font-size: 15px; min-height: 44px; padding: 10px 12px; }

/* Type Toggle */
.type-toggle { display: flex; gap: 1px; background: var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.type-btn { flex: 1; padding: 8px; border: none; font-size: 13px; font-weight: 600; cursor: pointer; background: var(--surface); color: var(--text-secondary); transition: all .12s; font-family: var(--font); }
.type-btn.active-expense { background: var(--red); color: #fff; }
.type-btn.active-income  { background: var(--green); color: #fff; }

/* Repeat mode toggle */
.active-repeat-mode { background: var(--accent) !important; color: var(--on-accent) !important; }

/* Total display */
.total-display { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; background: var(--accent-soft); border: 1.5px solid var(--accent-border); border-radius: var(--radius-sm); }
.total-label { font-size: 11px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .4px; }
.total-value { font-size: 22px; font-weight: 800; color: var(--accent); letter-spacing: -.5px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 5px; padding: 7px 13px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 600; border: 1px solid transparent; cursor: pointer; transition: all .12s; font-family: var(--font); white-space: nowrap; -webkit-tap-highlight-color: transparent; }
.btn:active { transform: scale(.97); }
.btn-block { display: flex; width: 100%; }
.btn-primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-secondary { background: var(--surface); color: var(--text-primary); border-color: var(--border-dark); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-danger { background: var(--red-bg); color: var(--red); border-color: var(--red-border); }
.btn-danger:hover { background: var(--red-hover); }
.btn-ghost { background: transparent; color: var(--text-secondary); border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--border); }
.btn-sm { padding: 5px 9px; font-size: 12px; }
.btn-lg { padding: 10px 18px; font-size: 14px; }
.btn-xl { padding: 11px 22px; font-size: 15px; min-height: 42px; }
.btn-icon { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: var(--radius-sm); font-size: 15px; text-decoration: none; transition: background .12s; }
.btn-icon:hover { background: var(--accent-soft); }

/* Import Rules */
.rule-list { display: flex; flex-direction: column; gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.rule-item { background: var(--surface); padding: 10px 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.rule-item:hover { background: var(--surface-2); }
.rule-keyword { font-size: 14px; font-weight: 600; }
.rule-target { font-size: 12px; color: var(--text-secondary); margin-top: 1px; }

/* Amount + currency side by side */
.form-stack { display: flex; flex-direction: column; gap: 14px; }
.form-row-amount { display: grid; grid-template-columns: 1fr 110px; gap: 12px; }
.form-control--amount { height: 50px; padding: 10px 12px; font-size: 20px; font-weight: 700; }
select.form-control--amount { font-size: 15px; }
.form-row-datesplit { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: end; }
.split-check { display: flex; align-items: center; gap: 9px; cursor: pointer; font-size: 14px; font-weight: 500; color: var(--text-primary); background: var(--surface); border: 1.5px solid var(--border-dark); border-radius: var(--radius-sm); padding: 0 12px; min-height: 44px; user-select: none; }
.split-check input[type="checkbox"] { width: 17px; height: 17px; cursor: pointer; accent-color: var(--accent); margin: 0; flex-shrink: 0; }
.split-preview { font-size: 13px; color: var(--text-secondary); margin-top: -6px; }
.btn-submit { margin-top: 8px; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }

/* Scrollable tables (mobile) */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Tags (Serie, Dauerauftrag) */
.tag-badge { display: inline-block; font-size: 10px; font-weight: 700; color: var(--text-secondary); background: var(--surface-2); border: 1px solid var(--border); border-radius: 99px; padding: 1px 7px; margin-left: 5px; vertical-align: middle; }

/* Series info box (edit modal) */
.series-box { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; background: var(--accent-soft); border: 1.5px solid var(--accent-border); border-radius: var(--radius-sm); padding: 10px 14px; }
.series-title { font-size: 13px; font-weight: 700; color: var(--accent-dark); }
.series-sub { font-size: 12px; color: var(--text-secondary); }
.series-actions { display: flex; gap: 6px; }

/* Section + chart headings */
.section-head { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--text-secondary); margin: 18px 2px 8px; }
.chart-head { padding: 14px 16px; font-size: 13px; font-weight: 700; border-bottom: 1px solid var(--border); }

/* KPI cards */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.kpi-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.kpi-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--text-muted); margin-bottom: 4px; }
.kpi-value { font-size: 18px; font-weight: 700; color: var(--text-primary); letter-spacing: -.3px; font-variant-numeric: tabular-nums; }
.kpi-value.kpi-green { color: var(--accent-dark); }
.kpi-value.kpi-red { color: var(--red); }
.kpi-sub { font-size: 11px; color: var(--text-secondary); margin-top: 3px; }
.kpi-sub a { font-weight: 600; }

/* Kategorie-Combobox */
.combo-wrap { position: relative; }
.combo-list { position: absolute; top: calc(100% + 2px); left: 0; right: 0; background: var(--surface); border: 1.5px solid var(--border-dark); border-radius: var(--radius-sm); box-shadow: var(--shadow-md); z-index: 650; max-height: 230px; overflow-y: auto; }
.combo-item { padding: 8px 12px; font-size: 14px; cursor: pointer; border-bottom: 1px solid var(--border); }
.combo-item:last-child { border-bottom: none; }
.combo-item:hover { background: var(--accent-soft); }
.combo-item-sub { color: var(--text-secondary); padding-left: 22px; }
.combo-new { font-size: 12px; color: var(--text-muted); font-style: italic; cursor: default; }
.combo-new:hover { background: var(--surface); }

/* Mini-Dialog (Nachfrage über dem Modal) */
.mini-overlay { position: fixed; inset: 0; background: var(--overlay); z-index: 800; display: flex; align-items: center; justify-content: center; padding: 16px; }
.mini-dialog { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-md); width: 100%; max-width: 420px; padding: 18px; animation: modalIn .18s ease-out; }
.mini-title { font-size: 15px; font-weight: 700; margin-bottom: 4px; }
.mini-text { font-size: 13px; color: var(--text-secondary); margin-bottom: 12px; }
.mini-option { display: flex; align-items: center; gap: 8px; font-size: 14px; padding: 5px 0; cursor: pointer; }
.mini-option input { width: 16px; height: 16px; }
.mini-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

/* Notes */
.note-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 8px; box-shadow: var(--shadow); }
.note-card:hover { border-color: var(--accent); }
.note-meta { font-size: 11px; color: var(--text-muted); margin-bottom: 6px; }
.note-content { font-size: 14px; line-height: 1.6; color: var(--text-primary); white-space: pre-wrap; word-break: break-word; }

/* Mobile */
@media (max-width: 640px) {
    .col-hide-mobile { display: none; }
    .toolbar { flex-direction: column; align-items: stretch; }
    .toolbar-divider { display: none; }
    .form-row-2 { grid-template-columns: 1fr; }
    .stats-bar { flex-direction: column; gap: 1px; }
    .modal { max-height: 90vh; overflow-y: auto; max-width: none; }
    .data-table thead th { padding: 8px 10px; font-size: 11px; }
    .data-table tbody td { padding: 8px 10px; font-size: 13px; }
    .td-desc { max-width: 120px; }
    .td-cat { max-width: 90px; }
    .header-date { font-size: .75rem; }
    .kpi-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
    .form-row-amount { grid-template-columns: 1fr 90px; }
    .form-row-datesplit { grid-template-columns: 1fr; }
    .series-box { flex-direction: column; align-items: stretch; }
}

/* ─── Seiten-Bausteine (Import, Regeln, Einstellungen) ─────────────────────── */
.page-narrow { max-width: 620px; margin: 0 auto; }
.page-medium { max-width: 820px; margin: 0 auto; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 14px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.card-title { font-size: 16px; font-weight: 700; margin-bottom: 10px; }
.card-text { font-size: 13px; color: var(--text-secondary); margin-bottom: 12px; }
.card-hint { font-size: 12px; color: var(--text-muted); margin-top: 12px; }
.muted { color: var(--text-muted); }
.loading { text-align: center; padding: 60px 20px; color: var(--text-muted); }
code { font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 3px; padding: 1px 5px; word-break: break-all; }
.field-hint { font-size: 12px; color: var(--text-muted); }

.drop-zone { border: 2px dashed var(--border-dark); border-radius: var(--radius); padding: 32px; text-align: center; cursor: pointer; transition: all .15s; }
.drop-zone:hover, .drop-zone.drag { border-color: var(--accent); background: var(--accent-soft); }

/* Segment-Schalter (z.B. Ausgabe / Einnahme / Beides) */
.seg { display: flex; gap: 1px; background: var(--border-dark); border: 1px solid var(--border-dark); border-radius: var(--radius-sm); overflow: hidden; }
.seg-btn { flex: 1; padding: 9px 8px; border: none; background: var(--surface); color: var(--text-secondary); font: 600 13px var(--font); cursor: pointer; }
.seg-btn:hover { background: var(--surface-2); }
.seg-btn.active { background: var(--accent); color: var(--on-accent); }

/* Filter-Chips */
.chip-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.chip { padding: 5px 12px; border-radius: 99px; border: 1.5px solid var(--border-dark); background: var(--surface); color: var(--text-secondary); font: 600 12px var(--font); cursor: pointer; }
.chip.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

/* Import-Vorschau */
.import-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.import-format { font-size: 12px; color: var(--text-secondary); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 7px 10px; margin-top: 10px; }
.import-table td { white-space: nowrap; }
.import-table .import-text { max-width: 360px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.import-table .import-cat { min-width: 190px; min-height: 32px; padding: 4px 28px 4px 8px; font-size: 13px; }
.import-table input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.import-table tr.row-nocat td .import-cat { border-color: var(--amber); background-color: var(--warn-bg); }
.import-table tr.row-off td { opacity: .45; }
.import-footer { position: sticky; bottom: 0; display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-md); padding: 10px 14px; margin-top: 12px; z-index: 5; }
.import-sum { font-size: 13px; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.import-sum .income { color: var(--positive); font-weight: 600; }
@media (max-width: 767px) { .import-footer { bottom: 62px; } }

/* Regeln */
.rules-tools { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.rules-tools .form-control { flex: 1; min-width: 180px; }
.rule-main { flex: 1; cursor: pointer; min-width: 0; }
.rule-cond { font-size: 12px; font-weight: 500; color: var(--text-secondary); margin-left: 6px; }
.rule-hits { font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.range-row { display: grid; grid-template-columns: 1fr auto 1fr auto; gap: 8px; align-items: center; font-size: 13px; color: var(--text-secondary); }
.rule-preview { font-size: 13px; color: var(--text-primary); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; }
.rule-preview ul { margin: 6px 0 0 18px; color: var(--text-secondary); font-size: 12px; }
.rule-sample { font-size: 12px; color: var(--text-secondary); background: var(--accent-soft); border: 1px solid var(--accent-border); border-radius: var(--radius-sm); padding: 8px 10px; word-break: break-word; }

/* Hinweis-Karte (z.B. Buchungen ohne Kategorie) */
.hint-card { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; background: var(--warn-bg); border: 1.5px solid var(--warn-border); border-radius: var(--radius); padding: 10px 14px; margin: 12px 0; font-size: 13px; }

/* Kategorien verwalten */
.cat-admin { display: flex; flex-direction: column; gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.cat-admin-item { background: var(--surface); padding: 8px 12px; }
.cat-admin-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cat-admin-name { font-weight: 700; font-size: 14px; }
.sub-chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.sub-chip { display: inline-flex; align-items: center; gap: 2px; font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 99px; padding: 2px 4px 2px 10px; }
.sub-chip button { border: none; background: none; cursor: pointer; color: var(--text-muted); font-size: 12px; padding: 0 4px; border-radius: 99px; }
.sub-chip button:hover { color: var(--text-primary); background: var(--border); }

/* Bottom-Nav bei vielen Einträgen seitlich scrollbar */
.bottom-nav { overflow-x: auto; }
.nav-item { min-width: 58px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* Entdecken (Dashboard) */
.explore-body { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 800px) { .explore-body { grid-template-columns: 1fr; } }
.explore-chart-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; margin-bottom: 8px; }
.explore-facts { display: flex; flex-direction: column; gap: 6px; }
.fact { font-size: 13px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; line-height: 1.45; }
.fact b { font-weight: 700; }
.explore-top { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 12px; }
.explore-top-row { display: grid; grid-template-columns: 86px minmax(0, 1fr) minmax(0, 180px) auto; gap: 10px; align-items: center; font-size: 13px; padding: 6px 8px; border-radius: var(--radius-sm); cursor: pointer; }
.explore-top-row:hover { background: var(--accent-soft); }
.explore-top-desc, .explore-top-cat { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 640px) { .explore-top-row { grid-template-columns: 76px minmax(0, 1fr) auto; } .explore-top-cat { display: none; } }
.chip-sub { font-weight: 500; opacity: .65; font-size: 11px; margin-left: 2px; }
.seg--sm .seg-btn { padding: 5px 10px; font-size: 12px; }
.explorer { margin-top: 14px; }

/* Export */
.export-box { display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap;
  background: var(--accent-soft); border: 1.5px solid var(--accent-border); border-radius: var(--radius); padding: 14px 16px; }
.export-box > div { flex: 1; min-width: 220px; }
.hint-card--blue { background: var(--info-bg); border-color: var(--info-border); }

/* ─── Icons ─────────────────────────────────────────────────────────────── */
.icon { width: 18px; height: 18px; flex-shrink: 0; vertical-align: -3px; }
.btn .icon { width: 16px; height: 16px; }
.btn-sm .icon { width: 14px; height: 14px; }
.icon-lg { width: 36px; height: 36px; }
.empty-icon { color: var(--text-muted); display: flex; justify-content: center; }
.empty-icon .icon { width: 36px; height: 36px; }
.fact { display: flex; gap: 9px; align-items: flex-start; }
.fact .icon { width: 17px; height: 17px; color: var(--accent); margin-top: 1px; }
.fact-text { flex: 1; min-width: 0; }
.tag-badge .icon { width: 11px; height: 11px; vertical-align: -1px; }
.card-title .icon { color: var(--accent); margin-right: 4px; }
.hint-card .icon { color: var(--text-secondary); margin-right: 4px; }
.seg-btn .icon { width: 14px; height: 14px; margin-right: 4px; vertical-align: -2px; }
.done-icon { color: var(--green); display: flex; justify-content: center; }
.done-icon .icon { width: 48px; height: 48px; }

/* ─── Kopfzeile / Navigation ────────────────────────────────────────────── */
.header { background: var(--header-bg); color: var(--header-text); }
.header-brand .icon { width: 22px; height: 22px; opacity: .9; }
.header-actions { display: flex; align-items: center; gap: .6rem; }
.header-btn { background: none; border: none; color: inherit; opacity: .8; cursor: pointer; padding: 6px; display: flex; border-radius: var(--radius-sm); }
.header-btn:hover { opacity: 1; background: rgba(255,255,255,.1); }
.header-btn .icon { width: 20px; height: 20px; }
a.sidebar-item { text-decoration: none; }
.nav-item .icon { width: 21px; height: 21px; }
.nav-item--main { color: var(--accent); }
.nav-plus { display: flex; align-items: center; justify-content: center; width: 38px; height: 26px; border-radius: 99px;
  background: var(--accent); color: var(--on-accent); margin-bottom: 1px; }
.nav-plus .icon { width: 18px; height: 18px; }
.bottom-nav { overflow-x: visible; }
.nav-item { min-width: 0; font-size: .68rem; }

/* «Mehr»-Menü als Bottom-Sheet */
.sheet-overlay { display: none; position: fixed; inset: 0; background: var(--overlay); z-index: 600; align-items: flex-end; }
.sheet-overlay.open { display: flex; }
.sheet { background: var(--surface); width: 100%; border-radius: 16px 16px 0 0; padding: 8px 12px calc(14px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-md); animation: sheetIn .18s ease-out; }
@keyframes sheetIn { from { transform: translateY(40px); opacity: .5; } to { transform: none; opacity: 1; } }
.sheet-handle { width: 40px; height: 4px; border-radius: 99px; background: var(--border-dark); margin: 4px auto 10px; }
.sheet-item { display: flex; align-items: center; gap: 14px; width: 100%; padding: 14px 10px; border: none; background: none;
  color: var(--text-primary); font: 500 16px var(--font); border-radius: var(--radius-sm); cursor: pointer; text-decoration: none; }
.sheet-item:hover, .sheet-item.active { background: var(--accent-soft); color: var(--accent); }
.sheet-item .icon { width: 22px; height: 22px; color: var(--text-secondary); }
.sheet-item.active .icon { color: var(--accent); }

/* ─── Anmeldeseite ──────────────────────────────────────────────────────── */
.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px 16px; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow-md); padding: 26px 24px; }
.auth-brand { display: flex; align-items: center; gap: 10px; color: var(--accent); font-weight: 700; font-size: 17px; margin-bottom: 18px; }
.auth-title { font-size: 22px; font-weight: 700; margin-bottom: 8px; }
.auth-text { font-size: 14px; color: var(--text-secondary); margin-bottom: 16px; }
.auth-error { background: var(--red-bg); border: 1px solid var(--red-border); color: var(--red); border-radius: var(--radius-sm);
  padding: 10px 12px; font-size: 14px; margin-bottom: 14px; }
.auth-code { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px;
  font-size: 13px; white-space: pre-wrap; }

/* ─── Einstellungen: Design & Modus ─────────────────────────────────────── */
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.theme-card { border: 2px solid var(--border); border-radius: var(--radius); padding: 8px; background: var(--surface);
  cursor: pointer; text-align: left; font: 600 13px var(--font); color: var(--text-primary); }
.theme-card.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
.theme-preview { display: grid; grid-template-rows: 14px 1fr; height: 64px; border-radius: 5px; overflow: hidden; margin-bottom: 6px; border: 1px solid rgba(0,0,0,.08); }
.theme-preview span:first-child { display: block; }
.theme-preview div { display: flex; gap: 5px; align-items: center; padding: 0 8px; }
.theme-preview i { display: block; height: 8px; border-radius: 4px; }
.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mode-card { border: 2px solid var(--border); border-radius: var(--radius); padding: 12px 14px; background: var(--surface);
  cursor: pointer; text-align: left; font-family: var(--font); color: var(--text-primary); }
.mode-card.active { border-color: var(--accent); background: var(--accent-soft); }
.mode-card strong { display: flex; align-items: center; gap: 6px; font-size: 14px; margin-bottom: 4px; }
.mode-card span { font-size: 12px; color: var(--text-secondary); }
@media (max-width: 480px) { .mode-grid { grid-template-columns: 1fr; } }

/* ─── Tablet ────────────────────────────────────────────────────────────── */
@media (min-width: 768px) and (max-width: 1100px) {
  .sidebar { width: 184px; padding: 1rem .5rem; }
  .sidebar-item { font-size: .85rem; padding: .6rem .6rem; }
  .main-content { padding: 1rem .9rem; }
  .explore-body { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}

/* ─── Handy ─────────────────────────────────────────────────────────────── */
@media (max-width: 767px) {
  .main-content { padding: .8rem max(.75rem, env(safe-area-inset-left)) calc(80px + env(safe-area-inset-bottom)); max-width: 100vw; }
  .header { height: 52px; }
  .header-date { display: none; }
  .bottom-nav { padding-bottom: env(safe-area-inset-bottom); }
  .nav-item { padding: .4rem .1rem .45rem; }

  /* grössere Touch-Ziele, keine Auto-Zoom-Sprünge auf iOS (min. 16px) */
  .form-control, .form-control--lg, select.form-control { font-size: 16px; min-height: 44px; }
  .form-control--amount { font-size: 22px; }
  .btn { min-height: 40px; }
  .btn-sm { min-height: 36px; padding: 6px 10px; }
  .chip { padding: 7px 12px; }
  .card { padding: 14px; }
  .toolbar { padding: 12px; }

  /* Dialoge als Bottom-Sheet */
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal { border-radius: 16px 16px 0 0; max-height: 92vh; display: flex; flex-direction: column; }
  .modal-body { overflow-y: auto; }
  .modal-footer { padding-bottom: calc(11px + env(safe-area-inset-bottom)); flex-wrap: wrap; }
  .mini-dialog { max-width: none; }

  /* Buchungsliste: Kategorie als zweite Zeile statt eigener Spalte */
  .data-table .td-cat, .data-table th.th-cat { display: none; }
  .td-sub { display: block !important; }
  .data-table tbody td.td-desc { white-space: normal; max-width: none; }
  .data-table tbody td { padding: 10px 8px; }
  .data-table thead th { padding: 8px; }
  .col-hide-mobile { display: none; }

  /* Import-Vorschau als Karten */
  .import-table thead { display: none; }
  .import-table tbody tr { display: grid; grid-template-columns: 30px minmax(0, 1fr) auto; grid-template-areas:
      "chk text amount" "chk date date" "cat cat rule"; gap: 4px 8px; padding: 10px; border-bottom: 1px solid var(--border); }
  .import-table tbody td { padding: 0 !important; background: none !important; white-space: normal; }
  .import-table td:nth-child(1) { grid-area: chk; padding-top: 2px !important; }
  .import-table td:nth-child(2) { grid-area: date; font-size: 12px; }
  .import-table td:nth-child(3) { grid-area: text; max-width: none; white-space: normal; font-weight: 600; }
  .import-table td:nth-child(4) { grid-area: amount; }
  .import-table td:nth-child(5) { grid-area: cat; }
  .import-table td:nth-child(6) { grid-area: rule; }
  .import-table .import-cat { min-width: 0; width: 100%; }
  .import-table tbody tr td[colspan] { grid-column: 1 / -1; }
  .import-footer { bottom: calc(62px + env(safe-area-inset-bottom)); border-radius: var(--radius); }
  .import-footer .btn-xl { flex: 1; }

  /* Entdecken */
  .explorer .chip-row { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
  .explorer .chip { flex-shrink: 0; }
  .explorer .card-head .seg { width: 100%; }
  .seg--sm .seg-btn { padding: 7px 4px; }

  .rule-item { flex-wrap: wrap; }
  .rule-main { flex-basis: 100%; }
  .cat-admin-head { row-gap: 6px; }
  .rules-tools .btn { flex: 1; }
  .kpi-value { font-size: 16px; }
  .stat-item { padding: 8px 12px; justify-content: space-between; }
  .export-box .btn { width: 100%; }
}
.td-sub { display: none; font-size: 12px; color: var(--text-secondary); margin-top: 1px; }

.sub-chip button .icon { width: 12px; height: 12px; }
.theme-card[data-theme] { background: var(--surface); color: var(--text-primary); }

@media (max-width: 767px) {
  .seg-btn { min-height: 38px; }
  .sub-chip { padding: 2px 2px 2px 10px; }
  .sub-chip button { min-width: 34px; min-height: 34px; display: inline-flex; align-items: center; justify-content: center; }
  .sub-chip button .icon { width: 15px; height: 15px; }
}

/* clip statt hidden: schneidet ab, ohne «position: sticky» (Import-Leiste) zu blockieren */
.main-content { overflow-x: clip; min-width: 0; }   /* min-width: breite Tabellen scrollen statt die Seite zu verbreitern */

/* ─── Einfach-Modus: Start-Dashboard ────────────────────────────────────── */
.simple-home { max-width: 720px; margin: 0 auto; }
.month-nav { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.month-nav-label { font-size: 20px; font-weight: 700; text-align: center; flex: 1; }
.month-nav-btn { width: 44px; height: 44px; padding: 0; border-radius: 99px; }
.month-nav-btn .icon { width: 20px; height: 20px; }
.big-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.big-stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 4px; }
.big-stat--main { grid-column: 1 / -1; background: var(--accent-soft); border-color: var(--accent-border); }
.big-label { font-size: 13px; font-weight: 600; color: var(--text-secondary); }
.big-value { font-size: 24px; font-weight: 800; letter-spacing: -.4px; font-variant-numeric: tabular-nums; }
.big-stat--main .big-value { font-size: 32px; }
.big-value.positive { color: var(--positive); }
.big-value.negative { color: var(--red); }
.simple-compare { font-size: 15px; color: var(--text-secondary); margin: 12px 4px 4px; line-height: 1.5; }
.simple-compare strong { color: var(--text-primary); }
.simple-home .card { margin-top: 14px; }
.simple-home .card-title { font-size: 17px; }
.simple-bars { display: flex; flex-direction: column; gap: 4px; }
.simple-bar { display: flex; flex-direction: column; gap: 6px; width: 100%; border: none; background: none; cursor: pointer;
  padding: 9px 8px; border-radius: var(--radius-sm); text-align: left; font: 15px var(--font); color: var(--text-primary); }
.simple-bar:hover { background: var(--surface-2); }
.simple-bar-top { display: flex; justify-content: space-between; gap: 10px; }
.simple-bar-top strong { font-variant-numeric: tabular-nums; white-space: nowrap; }
.simple-bar-track { height: 10px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.simple-bar-track span { display: block; height: 100%; border-radius: 99px; background: var(--accent); }
.simple-list { display: flex; flex-direction: column; }
.simple-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; width: 100%; border: none;
  background: none; border-bottom: 1px solid var(--border); padding: 11px 6px; cursor: pointer; text-align: left;
  font: 15px var(--font); color: var(--text-primary); }
.simple-row:last-child { border-bottom: none; }
.simple-row:hover { background: var(--surface-2); }
.simple-row-main { display: flex; flex-direction: column; min-width: 0; }
.simple-row-desc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.simple-row-sub { font-size: 13px; color: var(--text-secondary); }
.simple-row .td-amount { white-space: nowrap; font-size: 15px; }
.simple-footer { text-align: center; font-size: 13px; color: var(--text-muted); margin: 18px 0 8px; }

/* Übersicht im Einfach-Modus */
.toolbar--simple { display: block; }
.toolbar--simple .month-nav { margin-bottom: 10px; }
.simple-filter .form-control { min-height: 44px; font-size: 15px; }

@media (max-width: 767px) {
  .big-value { font-size: 20px; }
  .big-stat--main .big-value { font-size: 28px; }
  .month-nav-label { font-size: 18px; }
}
.big-stat--neg { background: var(--red-bg); border-color: var(--red-border); }
