/* Buchhaltung · Design „Tiefer Raum, sauberer Pegel“
   Hell und dunkel. Farben nur über die Variablen unten, damit Diagramme und Seiten zusammenpassen.
   Einnahmen = Türkis, Ausgaben = Koralle, Akzent = Indigo. Grün/Gelb/Rot nur für Status (wie am Pegelmeter). */
:root {
  color-scheme: light;
  --bg: #f4f5fa;
  --bg-glow: rgba(99, 110, 240, .10);
  --surface: #ffffff;
  --surface-2: #eef0f6;
  --field: #ffffff;
  --border: #e0e3ee;
  --text: #151a2d;
  --text-2: #5a6280;
  --accent: #4f5bd5;
  --accent-text: #ffffff;
  --accent-soft: #eceefd;
  --income: #0f95a3;
  --expense: #e2643a;
  --profit: #4f5bd5;
  --grid: #e7e9f1;
  --ok: #0b7a45;
  --ok-bg: #e1f4ea;
  --warn: #8a5800;
  --warn-bg: #fbefd4;
  --danger: #b4261b;
  --danger-bg: #fde6e3;
  --info-bg: #eceefd;
  --meter-ok: #22b36b;
  --meter-warn: #e9a91f;
  --meter-danger: #e5483b;
  --shadow: 0 1px 2px rgba(21, 26, 45, .04), 0 4px 16px rgba(21, 26, 45, .04);
  --stars: none;
  --radius: 14px;
  --radius-sm: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #090c17; --bg-glow: rgba(110, 120, 255, .13); --surface: #111627; --surface-2: #1a2035; --field: #0d1222;
    --border: #242b44; --text: #e8eaf4; --text-2: #9aa2bd; --accent: #8c96ff; --accent-text: #0a0d1a; --accent-soft: #1d2246;
    --income: #44cfdc; --expense: #ff8c5f; --profit: #8c96ff; --grid: #1d2338;
    --ok: #52d08c; --ok-bg: #10291f; --warn: #f3bc50; --warn-bg: #2e2412; --danger: #ff7b71; --danger-bg: #3a1619; --info-bg: #1a1f40;
    --meter-ok: #3fcf7f; --meter-warn: #f3bc50; --meter-danger: #ff6a5f;
    --shadow: 0 1px 0 rgba(255, 255, 255, .03) inset, 0 8px 24px rgba(0, 0, 0, .25); --stars: block;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #090c17; --bg-glow: rgba(110, 120, 255, .13); --surface: #111627; --surface-2: #1a2035; --field: #0d1222;
  --border: #242b44; --text: #e8eaf4; --text-2: #9aa2bd; --accent: #8c96ff; --accent-text: #0a0d1a; --accent-soft: #1d2246;
  --income: #44cfdc; --expense: #ff8c5f; --profit: #8c96ff; --grid: #1d2338;
  --ok: #52d08c; --ok-bg: #10291f; --warn: #f3bc50; --warn-bg: #2e2412; --danger: #ff7b71; --danger-bg: #3a1619; --info-bg: #1a1f40;
  --meter-ok: #3fcf7f; --meter-warn: #f3bc50; --meter-danger: #ff6a5f;
  --shadow: 0 1px 0 rgba(255, 255, 255, .03) inset, 0 8px 24px rgba(0, 0, 0, .25); --stars: block;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0; min-height: 100vh; color: var(--text);
  background: radial-gradient(1200px 420px at 50% -120px, var(--bg-glow), transparent 70%) no-repeat, var(--bg);
  font: 15px/1.5 system-ui, -apple-system, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
/* Sternenhimmel, nur im Dunkelmodus und nur angedeutet */
body::before {
  content: ""; display: var(--stars); position: fixed; inset: 0; z-index: -1; pointer-events: none; opacity: .55;
  background-image:
    radial-gradient(1px 1px at 12% 18%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 78% 12%, #cfd4ff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 64% 34%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 30% 62%, #bfefff 50%, transparent 51%),
    radial-gradient(1px 1px at 88% 70%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 46% 88%, #cfd4ff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 6% 82%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 94% 40%, #fff 50%, transparent 51%);
  background-size: 640px 640px;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
h1 { font-size: 1.6rem; line-height: 1.2; font-weight: 700; letter-spacing: -.02em; margin: 0 0 1rem; }
h2 { font-size: 1.05rem; font-weight: 650; letter-spacing: -.01em; margin: 1.5rem 0 .75rem; }
.muted { color: var(--text-2); }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.neg { color: var(--danger); }
code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .9em; }

/* Layout */
.topbar {
  position: sticky; top: 0; z-index: 20; padding-top: env(safe-area-inset-top);
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  -webkit-backdrop-filter: saturate(160%) blur(14px); backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner { max-width: 1160px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 1.25rem; }
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; letter-spacing: -.01em; color: var(--text); padding: .7rem 0; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 28px; height: 28px; flex: none; border-radius: 8px; display: block; }
nav.main { display: flex; gap: .1rem; overflow-x: auto; scrollbar-width: none; flex: 1; }
nav.main::-webkit-scrollbar { display: none; }
nav.main a {
  color: var(--text-2); padding: .4rem .65rem; margin: .55rem 0; white-space: nowrap; border-radius: 99px; font-size: .92rem;
}
nav.main a:hover { text-decoration: none; color: var(--text); background: var(--surface-2); }
nav.main a.active { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.theme-toggle {
  min-height: 36px; width: 36px; padding: 0; border-radius: 99px; flex: none;
  background: transparent; color: var(--text-2); border: 1px solid var(--border);
}
.theme-toggle:hover { color: var(--text); background: var(--surface-2); }
.theme-toggle svg { width: 18px; height: 18px; }
main { max-width: 1160px; margin: 0 auto; padding: 1.5rem 16px 4rem; }

/* Untere Leiste am Handy */
.tabbar { display: none; }
@media (max-width: 760px) {
  nav.main { display: none; }
  .topbar-inner { justify-content: space-between; }
  .brand { padding: .55rem 0; }
  main { padding: 1.1rem 16px calc(84px + env(safe-area-inset-bottom)); }
  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    padding: 4px 6px calc(4px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    -webkit-backdrop-filter: saturate(160%) blur(16px); backdrop-filter: saturate(160%) blur(16px);
    border-top: 1px solid var(--border);
  }
  .tabbar > a, .tabbar > details > summary {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0 4px;
    color: var(--text-2); font-size: .7rem; font-weight: 500; border-radius: 12px; list-style: none; cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .tabbar > details { flex: 1; display: flex; }
  .tabbar > details > summary::-webkit-details-marker { display: none; }
  .tabbar svg { width: 24px; height: 24px; }
  .tabbar a:hover { text-decoration: none; }
  .tabbar .active, .tabbar details[open] > summary { color: var(--accent); }
  .tabbar .active svg { filter: drop-shadow(0 0 6px color-mix(in srgb, var(--accent) 45%, transparent)); }
  .more-sheet {
    position: fixed; left: 10px; right: 10px; bottom: calc(70px + env(safe-area-inset-bottom));
    background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 6px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .28); display: grid; grid-template-columns: 1fr 1fr; gap: 2px;
  }
  .more-sheet a { color: var(--text); padding: .8rem .9rem; border-radius: 12px; font-weight: 500; }
  .more-sheet a.active { color: var(--accent); background: var(--accent-soft); }
  .more-sheet a:hover { text-decoration: none; background: var(--surface-2); }
}

/* Bausteine */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
}
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.kpis { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-bottom: 1rem; }
.kpi { position: relative; overflow: hidden; }
.kpi .label { color: var(--text-2); font-size: .82rem; font-weight: 500; line-height: 1.3; }
.kpi .label::before {
  content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 99px; margin-right: .45rem; vertical-align: .05em;
  background: var(--kpi-color, var(--text-2));
}
.kpi.income { --kpi-color: var(--income); }
.kpi.expense { --kpi-color: var(--expense); }
.kpi.profit { --kpi-color: var(--profit); }
.kpi.limit { --kpi-color: var(--meter-ok); }
.kpi .value { font-size: 1.6rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; margin-top: .15rem; }
.kpi .sub { color: var(--text-2); font-size: .8rem; font-variant-numeric: tabular-nums; }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: .75rem; }
.eyebrow { color: var(--text-2); font-size: .85rem; font-weight: 500; margin-bottom: .15rem; }

.flash {
  padding: .65rem .9rem; border-radius: var(--radius-sm); margin-bottom: .75rem; background: var(--ok-bg); color: var(--ok);
  border-left: 3px solid currentColor;
}
.flash a { color: inherit; font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
.flash.error { background: var(--danger-bg); color: var(--danger); }
.flash.info { background: var(--info-bg); color: var(--text); border-left-color: var(--accent); }
.flash.info a { color: var(--accent); }
.flash.warn { background: var(--warn-bg); color: var(--warn); }
.flash.danger { background: var(--danger-bg); color: var(--danger); }

.badge {
  display: inline-block; font-size: .74rem; font-weight: 600; padding: .12rem .55rem; border-radius: 99px;
  background: var(--surface-2); color: var(--text-2);
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.badge.claude { background: var(--info-bg); color: var(--accent); }

/* Tabellen */
.table-wrap { overflow-x: auto; }
.card.table-wrap { padding: .25rem .5rem; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .6rem .5rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
tr:last-child > td, tr:last-child > th { border-bottom: 0; }
th { font-size: .82rem; color: var(--text-2); font-weight: 600; }
tbody tr:has(> th.num) > th { color: var(--text); font-size: .95rem; font-weight: 700; border-top: 2px solid var(--border); }
thead th { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; }
tr.cancelled td { color: var(--text-2); text-decoration: line-through; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }

/* Formulare */
label { display: block; font-size: .84rem; color: var(--text-2); font-weight: 500; margin-bottom: .25rem; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--field);
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .55rem .7rem; min-height: 44px;
  transition: border-color .15s, box-shadow .15s;
}
input[type="file"] { padding: .5rem; }
input[type="checkbox"], input[type="radio"] {
  width: 1.3rem; height: 1.3rem; min-height: 0; padding: 0; flex: none; accent-color: var(--accent); cursor: pointer;
}
input::file-selector-button {
  font: inherit; font-weight: 600; margin-right: .75rem; padding: .35rem .8rem; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); cursor: pointer;
}
textarea { min-height: 80px; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}
.fields { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.fields .wide { grid-column: 1 / -1; }
button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: inherit; font-weight: 600; cursor: pointer; border-radius: var(--radius-sm); padding: .55rem 1.05rem; min-height: 44px;
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-text);
  transition: filter .15s, background .15s, transform .05s;
}
button:hover, .button:hover { filter: brightness(1.08); }
button:active, .button:active { transform: translateY(1px); }
button.secondary, .button.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
button.secondary:hover, .button.secondary:hover { filter: none; background: var(--surface-2); }
button.danger { background: var(--surface); color: var(--danger); border-color: var(--danger); }
button.danger:hover { filter: none; background: var(--danger-bg); }
button.small, .button.small { min-height: 34px; padding: .25rem .7rem; font-size: .85rem; }
.button:hover { text-decoration: none; }
form.inline { display: inline; }
details > summary { cursor: pointer; color: var(--accent); font-weight: 500; }
details.card > summary { margin: -.15rem 0; }

/* Belege */
.dropzone {
  border: 2px dashed color-mix(in srgb, var(--accent) 35%, var(--border)); border-radius: var(--radius); padding: 1.75rem 1rem;
  text-align: center; background: color-mix(in srgb, var(--accent-soft) 45%, var(--surface));
}
.dropzone.drag { border-color: var(--accent); background: var(--info-bg); }
.doc-list { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.doc-card { display: block; color: var(--text); transition: border-color .15s, transform .15s; }
.doc-card:hover { text-decoration: none; border-color: var(--accent); }
.doc-thumb {
  height: 140px; border-radius: var(--radius-sm); background: var(--surface-2); display: flex; align-items: center;
  justify-content: center; overflow: hidden; margin-bottom: .6rem; color: var(--text-2); font-weight: 600;
}
.doc-thumb img { width: 100%; height: 100%; object-fit: cover; }
.preview { width: 100%; height: 70vh; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
img.preview { object-fit: contain; }
.split { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 900px) { .split { grid-template-columns: 1.1fr 1fr; } }

.chart-box { position: relative; height: 260px; }
.card > h2:first-child { margin-top: 0; }

/* Pegelanzeige (z.B. Kleinunternehmergrenze): Farbe hängt an der Position, wie am VU-Meter */
.meter {
  position: relative; height: 12px; margin: .45rem 0; border-radius: 3px; overflow: hidden;
  background: linear-gradient(90deg, var(--meter-ok) 0 72%, var(--meter-warn) 80% 94%, var(--meter-danger) 100%);
  -webkit-mask: repeating-linear-gradient(90deg, #000 0 5px, transparent 5px 7px);
  mask: repeating-linear-gradient(90deg, #000 0 5px, transparent 5px 7px);
}
.meter > span { position: absolute; top: 0; right: 0; bottom: 0; background: var(--surface-2); }
/* alte Klasse bleibt nutzbar */
.progress { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); }
.progress.warn > div { background: var(--warn); }
.progress.danger > div { background: var(--danger); }

pre.ocr { white-space: pre-wrap; font-size: .8rem; max-height: 240px; overflow: auto; background: var(--surface-2); padding: .75rem; border-radius: var(--radius-sm); }
.qr svg { width: 220px; height: 220px; background: #fff; padding: 8px; border-radius: var(--radius-sm); }
.qr svg path { fill: #000; }
.auth { max-width: 420px; margin: 7vh auto 0; }
.auth-brand { text-align: center; margin-bottom: 1.25rem; }
.auth-brand .brand-mark { width: 64px; height: 64px; border-radius: 16px; margin: 0 auto .75rem; box-shadow: 0 10px 30px var(--bg-glow); }
.auth button[type="submit"] { width: 100%; }
.auth-brand .tagline { color: var(--text-2); font-size: .9rem; }
code.token { display: block; word-break: break-all; padding: .6rem; background: var(--surface-2); border-radius: var(--radius-sm); }
.show-sm { display: none; }
@media (max-width: 600px) {
  .hide-sm { display: none; }
  .show-sm { display: block; }
  th, td { padding: .55rem .35rem; }
  td { -webkit-hyphens: auto; hyphens: auto; overflow-wrap: anywhere; }
  h1 { font-size: 1.4rem; }
  .card { padding: .9rem; }
  .kpi .value { font-size: 1.25rem; }
  .kpis { grid-template-columns: 1fr 1fr; gap: .75rem; }
}

/* Zeitraumwahl */
.period { display: flex; flex-direction: column; gap: .5rem; }
.period-main { display: flex; gap: .4rem; align-items: center; }
.period-main select { width: auto; }
.period .step { padding: .55rem .85rem; font-size: 1.15rem; line-height: 1; }
.period-custom { display: flex; gap: .5rem; align-items: flex-end; flex-wrap: wrap; }
.period-custom label { margin: 0; }
.period-custom input { width: auto; }
.period [hidden] { display: none !important; }
.page-head { display: flex; gap: .75rem; align-items: flex-end; flex-wrap: wrap; margin-bottom: 1.1rem; }
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--text-2); font-size: .85rem; }
@media (max-width: 600px) {
  .page-head .period, .page-head .period-main { width: 100%; }
  .period-main select { flex: 1; min-width: 0; }
  .period-custom label { flex: 1; min-width: 0; }
  .period-custom input { width: 100%; }
  .period-custom button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
