/* cgs-books — app styles. Mobile-first, responsive, no framework. */
/* Farbschema an CGS-Cockpit angelehnt: dark-first, gunmetal-blau, gedämpftes
   Grün/Rot, near-black Ebenen (nicht Reingrün-Weiss wie zuvor). */
:root {
  --bg: #0a0b0d;            /* Seite (near-black base) */
  --surface: #15171c;       /* Karten */
  --sidebar-bg: #101217;    /* Seitenleiste */
  --ink: #f2f3f5;
  --muted: #a8acb4;
  --line: #2a2d34;
  --brand: #4c7eff;         /* gunmetal-optics blue */
  --brand-ink: #ffffff;
  --income: #34c77b;
  --expense: #e5484d;
  --accent: #4c7eff;
  --warn: #e8a33d;
  --radius: 12px;
  --shadow: 0 8px 24px rgba(0,0,0,.45);
  --maxw: 960px;
  color-scheme: dark;
  font-size: 16px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--ink); line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}
[x-cloak] { display: none !important; }
h1,h2,h3 { margin: 0 0 .4em; font-weight: 650; }
a { color: var(--accent); }
button { font: inherit; cursor: pointer; }

/* ---- Layout ---- */
.app { max-width: var(--maxw); margin: 0 auto; padding: 0 12px 96px; }
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--brand); color: var(--brand-ink);
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; box-shadow: var(--shadow);
}
.topbar .brand { font-weight: 700; letter-spacing: .2px; }
.topbar .who { font-size: .8rem; opacity: .85; }
.topbar button { background: transparent; color: inherit; border: 1px solid rgba(255,255,255,.4);
  border-radius: 8px; padding: 4px 10px; font-size: .8rem; }

/* ---- Tabs ---- */
.tabs { display: flex; gap: 4px; overflow-x: auto; position: sticky; top: 52px; z-index: 10;
  background: var(--bg); padding: 8px 0; }
.tabs button {
  flex: 0 0 auto; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 999px; padding: 8px 16px; font-size: .9rem; white-space: nowrap;
}
.tabs button.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ---- Sidebar layout (left banner) ---- */
.shell { display: flex; align-items: stretch; min-height: 100vh; }
.sidebar {
  flex: 0 0 220px; width: 220px; background: var(--sidebar-bg); color: var(--ink);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 6px; padding: 14px 12px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.side-brand { padding: 4px 6px 14px; display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.brand-logo { width: 150px; max-width: 100%; height: auto; display: block; }
.brand-product { font-size: .72rem; letter-spacing: .2em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.sidenav { display: flex; flex-direction: column; gap: 4px; }
.sidenav button {
  text-align: left; background: transparent; color: var(--ink); border: 1px solid transparent;
  border-radius: 8px; padding: 10px 12px; font-size: .92rem; display: flex; align-items: center; gap: 8px;
}
.sidenav button:hover { background: rgba(255,255,255,.06); }
.sidenav button.active { background: rgba(76,126,255,.16); color: #cfe0ff; border-color: rgba(76,126,255,.4); font-weight: 600; }
.side-filters { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.side-filters .field { margin-bottom: 8px; }
.side-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 8px; }
.side-foot .who { font-size: .82rem; color: var(--muted); }
.side-foot button { background: transparent; color: var(--ink); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 10px; font-size: .82rem; }
.main { flex: 1 1 auto; min-width: 0; }
/* Inhalt an der Seitenleiste ausrichten (nicht mittig) + Luft nach oben. */
.main .app { margin: 0; max-width: 1180px; padding: 64px 16px 96px; }
/* Breite Tabellen (Kontoauszug „Alle Konten") auf schmalen Screens scrollbar statt gequetscht. */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll > table { min-width: 560px; }
.mobilebar { display: none; }
.hamb { background: transparent; border: none; color: var(--ink); font-size: 1.5rem; line-height: 1; padding: 0 6px; cursor: pointer; }
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 55; }
@media (min-width: 821px) { .backdrop { display: none !important; } }
@media (max-width: 820px) {
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 60; height: 100vh; width: 250px; flex-basis: 250px;
    transform: translateX(-100%); transition: transform .22s ease; box-shadow: 0 0 24px rgba(0,0,0,.35);
  }
  .sidebar.open { transform: none; }
  .mobilebar {
    display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 40;
    background: var(--sidebar-bg); color: var(--ink); border-bottom: 1px solid var(--line);
    padding: 10px 14px;
  }
  .mobilebar .brand { font-weight: 700; color: var(--brand); }
}

/* ---- Berichte: Kosten-Tortendiagramm ---- */
.rpt-row { display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap; }
.rpt-main { flex: 2 1 340px; min-width: 0; }
.rpt-side { flex: 1 1 260px; min-width: 240px; }
.pie-wrap { display: flex; justify-content: center; padding: 6px 0 4px; }
.pie { width: 172px; height: 172px; border-radius: 50%; position: relative; }
.pie-center { position: absolute; inset: 25%; background: var(--surface); border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.pie-center strong { font-size: .92rem; font-variant-numeric: tabular-nums; }
.legend { margin-top: 10px; font-size: .82rem; }
.legend-row { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.legend-row .dot { width: 11px; height: 11px; border-radius: 3px; flex: 0 0 auto; }
.legend-row .lg-amt { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--muted); }

/* ---- Cards / panels ---- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.grow { flex: 1 1 160px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label { font-size: .78rem; color: var(--muted); font-weight: 600; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
textarea { resize: vertical; min-height: 60px; }

/* ---- Buttons ---- */
.btn { border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 10px; padding: 10px 16px; font-weight: 600; }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.danger { background: var(--expense); color: #fff; border-color: var(--expense); }

/* Sticky Aktionsleiste über den Buchungen: zwei getippte Buttons (Einnahme/
   Ausgabe), bleibt beim Scrollen oben; darunter eine dünne Trennlinie.
   WICHTIG: die Buchungen-Seite hat KEIN .app-padding-top (siehe .app.tab-ledger),
   der Abstand oben kommt aus dieser Leiste (padding-top). So sitzen die Buttons
   im gescrollten UND ungescrollten Zustand an DERSELBEN Stelle — kein Sprung. */
.ledger-bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; gap: 10px; flex-wrap: wrap;
  background: var(--bg); padding: 48px 0 28px; margin-bottom: 16px;
  border-bottom: 1px solid rgba(255,255,255,.16);
}
.main .app.tab-ledger { padding-top: 0; }
.ledger-bar .btn { flex: 0 1 auto; font-weight: 700; letter-spacing: .04em; padding: 34px 22px; }
.btn.act-income  { color: var(--income);  border-color: var(--income);  background: transparent; }
.btn.act-income:hover  { background: rgba(52,199,123,.12); }
.btn.act-expense { color: var(--expense); border-color: var(--expense); background: transparent; }
.btn.act-expense:hover { background: rgba(229,72,77,.12); }
@media (max-width: 640px) { .ledger-bar .btn { flex: 1 1 auto; } }
.btn.ghost { background: transparent; }
.btn.sm { padding: 6px 10px; font-size: .82rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.fab { position: fixed; right: 18px; bottom: 22px; z-index: 30; border-radius: 999px;
  padding: 14px 20px; font-size: 1rem; box-shadow: 0 4px 14px rgba(0,0,0,.25); }

/* ---- Totals bar ---- */
.totals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.totals .t { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px; text-align: center; }
.totals .t .lbl { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.totals .t .val { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.val.income { color: var(--income); }
.val.expense { color: var(--expense); }

/* ---- Entry list ---- */
.entry { display: flex; align-items: center; gap: 12px; padding: 12px 6px; border-bottom: 1px solid var(--line); }
.entry:last-child { border-bottom: 0; }
.entry .meta { flex: 1 1 auto; min-width: 0; }
.entry .meta .desc { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry .meta .sub { font-size: .78rem; color: var(--muted); }
.entry .amt { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.entry .amt.income { color: var(--income); }
.entry .amt.expense { color: var(--expense); }
.badge { display: inline-block; font-size: .68rem; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.badge.lock, .badge.due { color: var(--warn); border-color: var(--warn); }
.badge.twint { color: var(--accent); border-color: var(--accent); }
.badge.bank { color: var(--muted); border-color: var(--line); }
.badge.sepa { color: #a78bfa; border-color: #a78bfa; }
.pin { font-size: .8rem; }
/* Beleg-Nr (Buchungsnummer) je Buchung — dezent, monospaced. */
.beleg { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .72rem;
  color: var(--muted); margin-right: 6px; }
/* Offene Debitoren-Rechnungen: rot markiert (AUSSTEHEND SEIT + offener Betrag). */
.ausstehend { color: var(--expense); font-weight: 600; }
.entry .amt.unpaid { color: var(--expense); }

/* ---- Tables (reports, desktop) ---- */
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 6px; text-align: left; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
td.num, th.num { text-align: right; }
tfoot td { font-weight: 700; }

/* ---- Modal ---- */
.modal-bg { position: fixed; inset: 0; background: rgba(10,12,16,.5); display: flex;
  align-items: flex-end; justify-content: center; z-index: 50; padding: 0; }
.modal { background: var(--surface); width: 100%; max-width: 560px; border-radius: 16px 16px 0 0;
  max-height: 92vh; overflow-y: auto; padding: 18px; }
@media (min-width: 640px) {
  .modal-bg { align-items: center; padding: 20px; }
  .modal { border-radius: 16px; }
  .totals { grid-template-columns: repeat(4, 1fr); }
}
.modal h2 { display: flex; justify-content: space-between; align-items: center; }
.modal .x { background: none; border: none; font-size: 1.5rem; color: var(--muted); line-height: 1; }

/* ---- Misc ---- */
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.right { text-align: right; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.stack > * + * { margin-top: 10px; }
.notice { padding: 10px 12px; border-radius: 10px; font-size: .88rem; margin-bottom: 12px; }
.notice.err { background: #2a1416; color: #f6a6a9; border: 1px solid #5a2a2e; }
.notice.ok  { background: #10261b; color: #6fe3a8; border: 1px solid #1f5238; }
.notice.warn { background: #2a2013; color: #f0c887; border: 1px solid #524122; }
/* Globale Rückmeldung (Speichern/Fehler) als fixierter Toast — sichtbar, egal wie weit gescrollt. */
.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 200;
  min-width: 240px; max-width: 90vw; margin: 0; box-shadow: var(--shadow); }
.receipt-thumb { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line);
  border-radius: 8px; padding: 4px 8px; font-size: .8rem; margin: 4px 4px 0 0; text-decoration: none; color: var(--ink); }
.login-wrap { max-width: 380px; margin: 12vh auto 0; }
.center { text-align: center; }
.hidden { display: none; }
.tag-income { color: var(--income); font-weight: 600; }
.tag-expense { color: var(--expense); font-weight: 600; }
.spin { display: inline-block; width: 1em; height: 1em; border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Reports: compact paid-figures + open-receivables summary under the pie */
.rpt-quick { margin-top: 12px; border-top: 1px solid rgba(255,255,255,.14); padding-top: 10px; }
.rpt-quick .q-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 3px 0; }
.rpt-quick .q-row .num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.rpt-quick .q-strong { font-weight: 600; }
.rpt-quick .q-open { margin-top: 6px; padding-top: 8px; border-top: 1px dashed rgba(255,255,255,.12); }
