:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #14213d;
  --text: #1f2633;
  --muted: #6b7383;
  --line: #e4e7ec;
  --accent: #fca311;
  --primary: #14213d;
  --green: #12805c;
  --green-bg: #e6f4ee;
  --red: #c0392b;
  --red-bg: #fbeaea;
  --blue: #2563eb;
  --blue-bg: #e8effd;
  --amber-bg: #fff4de;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  font-size: 15px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
a { color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.pos { color: var(--green); }
.neg { color: var(--red); }
.error { color: var(--red); min-height: 1.2em; }

/* Icons */
i[data-icon] { display: inline-flex; width: 20px; height: 20px; flex: none; }
i[data-icon] svg { width: 100%; height: 100%; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: var(--ink); }
.login-card { background: var(--card); padding: 32px; border-radius: 16px; width: 100%; max-width: 360px; display: grid; gap: 14px; }
.login-card p { margin: 0; }

/* Layout */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar { background: var(--ink); color: #dfe3ea; padding: 18px 12px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; padding: 0 8px; color: #fff; }
.brand.big { color: var(--ink); font-size: 24px; padding: 0; }
.logo { width: 32px; height: 32px; border-radius: 9px; background: var(--accent); color: var(--ink); display: grid; place-items: center; font-weight: 800; }
#nav { display: grid; gap: 2px; }
#nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 9px; text-decoration: none; color: #c5ccd8; }
#nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
#nav a.active { background: rgba(252, 163, 17, .15); color: #fff; }
#nav a.active i { color: var(--accent); }
.badge { margin-left: auto; background: var(--red); color: #fff; border-radius: 99px; font-size: 11px; padding: 2px 7px; }
.logout { margin-top: auto; color: #c5ccd8 !important; justify-content: flex-start; }
main { padding: 28px 32px 100px; max-width: 1280px; width: 100%; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { margin: 0; font-size: 24px; color: var(--ink); }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Cards & Grid */
.grid { display: grid; gap: 16px; }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; min-width: 0; }
.card h2 { font-size: 15px; margin: 0 0 14px; color: var(--ink); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush h2 { padding: 16px 18px 0; }
.kpi .label { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 8px; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; color: var(--ink); }
.kpi .value.neg { color: var(--red); }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.kpi.dark { background: var(--ink); color: #fff; border-color: var(--ink); }
.kpi.dark .label, .kpi.dark .sub { color: #aab3c5; }
.kpi.dark .value { color: #fff; }
.acc-ico { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; background: var(--bg); color: var(--ink); }
.acc-ico i { width: 16px; height: 16px; }
.mt { margin-top: 16px; }

/* Buttons & Forms */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: var(--card); color: var(--text); padding: 9px 14px; border-radius: 9px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: #c9ced8; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: #1d2f57; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: var(--ink); }
.btn.danger { color: var(--red); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .6; cursor: default; }
label { display: grid; gap: 5px; font-size: 13px; color: var(--muted); font-weight: 600; }
input, select, textarea { font: inherit; color: var(--text); border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; background: #fff; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(252, 163, 17, .45); border-color: var(--accent); }
textarea { resize: vertical; min-height: 64px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 500; font-size: 14px; }
.check input { width: 18px; height: 18px; }
.seg { display: flex; background: var(--bg); padding: 4px; border-radius: 11px; gap: 4px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 8px 10px; border-radius: 8px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button.on { background: #fff; color: var(--ink); box-shadow: var(--shadow); }
.seg button.on[data-v="expense"] { color: var(--red); }
.seg button.on[data-v="income"] { color: var(--green); }
.seg button.on[data-v="transfer"] { color: var(--blue); }
.amount-input { font-size: 22px; font-weight: 700; text-align: right; }
.vat-hint { font-size: 12px; color: var(--muted); text-align: right; }

/* Filter */
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.filters > * { width: auto; flex: 0 1 auto; }
.filters input[type=search] { flex: 1 1 220px; }

/* Table */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 11px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: #fafbfc; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #fafbfc; }
tbody tr:last-child td { border-bottom: 0; }
tfoot td { font-weight: 700; background: #fafbfc; }
.cell-main { font-weight: 600; }
.cell-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill.open { background: var(--amber-bg); color: #9a5b00; }
.pill.overdue { background: var(--red-bg); color: var(--red); }
.pill.paid { background: var(--green-bg); color: var(--green); }
.pill.transfer { background: var(--blue-bg); color: var(--blue); }
.pill.off { background: var(--bg); color: var(--muted); }
.clip { color: var(--muted); display: inline-flex; align-items: center; gap: 3px; font-size: 12px; }
.clip i { width: 14px; height: 14px; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-top: 1px solid var(--line); }

/* Listen */
.list { display: grid; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .grow .cell-main { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Balken (Kategorien) */
.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; margin-bottom: 12px; font-size: 14px; }
.bar-track { grid-column: 1 / -1; height: 6px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--ink); border-radius: 99px; }
.bar-fill.inc { background: var(--green); }

/* Chart */
.chart svg { width: 100%; height: auto; display: block; }
.chart .legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-top: 8px; flex-wrap: wrap; }
.chart .legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; background: var(--c); vertical-align: -1px; }
.chart-tip { position: fixed; pointer-events: none; background: var(--ink); color: #fff; padding: 8px 10px; border-radius: 8px; font-size: 12px; z-index: 50; line-height: 1.5; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(20, 33, 61, .45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; z-index: 30; }
.modal { background: var(--card); border-radius: 16px; width: 100%; max-width: 640px; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
.modal.wide { max-width: 820px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 18px; color: var(--ink); }
.modal-body { padding: 20px; display: grid; gap: 16px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.modal-foot .left { margin-right: auto; }

/* Belege */
.att-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.att { position: relative; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; aspect-ratio: 3 / 4; background: var(--bg); display: grid; place-items: center; text-decoration: none; }
.att img { width: 100%; height: 100%; object-fit: cover; }
.att .pdf { font-weight: 800; color: var(--red); font-size: 13px; text-align: center; padding: 6px; word-break: break-word; }
.att .x { position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: rgba(0, 0, 0, .6); color: #fff; cursor: pointer; display: grid; place-items: center; font-size: 15px; line-height: 1; }
.att.new { outline: 2px dashed var(--accent); outline-offset: -2px; }
.att-add { display: flex; gap: 8px; flex-wrap: wrap; }
.att-add input { display: none; }

/* Toast & FAB */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(120px); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 10px; transition: transform .25s, opacity .25s; opacity: 0; z-index: 60; max-width: calc(100% - 32px); }
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.err { background: var(--red); }
.fab { position: fixed; right: 28px; bottom: 28px; width: 58px; height: 58px; border-radius: 50%; border: 0; background: var(--accent); color: var(--ink); box-shadow: 0 8px 20px rgba(252, 163, 17, .45); cursor: pointer; display: grid; place-items: center; z-index: 20; }
.fab i { width: 26px; height: 26px; }

.year-select { width: auto; }
.vat-table td, .vat-table th { padding: 8px 10px; }
.settings-section + .settings-section { margin-top: 16px; }
.row-edit { display: grid; grid-template-columns: 1.4fr 1fr 1fr auto; gap: 8px; align-items: end; padding: 10px 0; border-bottom: 1px solid var(--line); }
.row-edit:last-child { border-bottom: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 6px 6px 12px; border: 1px solid var(--line); border-radius: 99px; font-size: 13px; background: #fff; }
.chip.archived { opacity: .5; }
.chip button { border: 0; background: var(--bg); border-radius: 50%; width: 22px; height: 22px; cursor: pointer; color: var(--muted); }

/* Mobil */
@media (max-width: 1100px) {
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-3 { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; bottom: 0; top: auto; left: 0; right: 0; height: auto; flex-direction: row; padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); z-index: 25; gap: 0; }
  .sidebar .brand, .logout { display: none; }
  #nav { grid-auto-flow: column; grid-auto-columns: 1fr; width: 100%; }
  #nav a { flex-direction: column; gap: 3px; font-size: 10.5px; padding: 6px 2px; position: relative; text-align: center; }
  #nav a .badge { position: absolute; top: 0; right: 18%; margin: 0; padding: 1px 5px; font-size: 10px; }
  main { padding: 18px 14px 110px; }
  .grid.cols-2 { grid-template-columns: 1fr; }
  .fab { bottom: calc(84px + env(safe-area-inset-bottom)); right: 18px; }
  .form-grid { grid-template-columns: 1fr; }
  .modal-bg { padding: 0; }
  .modal { border-radius: 0; min-height: 100vh; }
  .hide-sm { display: none; }
  th, td { padding: 10px; }
  .row-edit { grid-template-columns: 1fr 1fr; }
  .kpi .value { font-size: 20px; }
}

/* ---------- Benutzer / Rollen ---------- */
.me { margin-top: auto; padding: 10px 12px; border-top: 1px solid rgba(255,255,255,.08); font-size: 13px; color: #c5ccd8; }
.me b { color: #fff; display: block; }
.logout { margin-top: 0; }
.login-card .link { background: none; border: 0; color: var(--muted); text-decoration: underline; cursor: pointer; font: inherit; padding: 0; justify-self: center; }
.code-input { font-size: 26px; letter-spacing: 10px; text-align: center; font-weight: 700; }
.notice { background: var(--amber-bg); color: #6b4300; border-radius: 10px; padding: 12px 14px; font-size: 14px; }
.notice.info { background: var(--blue-bg); color: #1e3a8a; }
.role-pill { font-size: 11px; padding: 2px 8px; border-radius: 99px; background: var(--bg); color: var(--muted); font-weight: 600; }
.role-pill.admin { background: #fde7c4; color: #8a4b00; }
.role-pill.user { background: var(--green-bg); color: var(--green); }
.role-pill.viewer { background: var(--blue-bg); color: var(--blue); }
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 6px 14px; max-height: 260px; overflow: auto; padding: 4px 2px; }
.cat-grid .check { font-size: 13.5px; }
.audit td { font-size: 13px; }
.audit code { font-size: 12px; color: var(--muted); word-break: break-all; }
.readonly .att .x { display: none; }
code { background: var(--bg); padding: 1px 5px; border-radius: 5px; }
@media (max-width: 820px) { .me { display: none; } }
.h2i { display: inline-flex; align-items: center; gap: 8px; }
