:root {
  --bg: #f5f6f8; --card: #fff; --text: #1d2330; --muted: #6b7385; --line: #e3e6ec;
  --primary: #1f6feb; --primary-d: #1859c2; --ok: #1a7f37; --warn: #9a6700; --err: #cf222e;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 0 0 12px; }
small, .muted { color: var(--muted); }

body.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: #111827; color: #cbd2df; padding: 18px 14px; display: flex; flex-direction: column; gap: 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar .logo { font-size: 24px; font-weight: 800; color: #fff; letter-spacing: -0.5px; }
.sidebar .logo span { color: var(--primary); }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a { color: #cbd2df; padding: 8px 10px; border-radius: 8px; }
.sidebar nav a:hover { background: #1f2937; text-decoration: none; color: #fff; }
.sidebar nav a.active { background: #1f2937; color: #fff; font-weight: 600; }
.sidebar nav a.btn { color: #fff; margin-bottom: 10px; text-align: center; }
.nav-sep { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #6b7385; margin: 14px 10px 4px; }
.company-switch label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #6b7385; }
.company-switch select { width: 100%; margin-top: 4px; background: #1f2937; color: #fff; border-color: #374151; }
.who { margin-top: auto; border-top: 1px solid #1f2937; padding-top: 12px; font-size: 13px; }
.who .link { color: #8b95a7; padding: 0; }
.content { padding: 28px 36px; max-width: 1280px; width: 100%; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 18px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }
.toolbar { display: flex; align-items: center; gap: 10px; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .left, .toolbar .right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
input, select, textarea { width: 100%; font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(31,111,235,.25); border-color: var(--primary); }
textarea { min-height: 70px; resize: vertical; }
input[type=checkbox] { width: auto; }
input[type=color] { padding: 2px; height: 38px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 500; color: var(--text); font-size: 14px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 3px; }

.btn, button { display: inline-block; font: inherit; font-weight: 600; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--text); cursor: pointer; white-space: nowrap; }
.btn:hover, button:hover { text-decoration: none; border-color: #c3c9d4; }
.btn.primary, button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover, button.primary:hover { background: var(--primary-d); }
.btn.danger, button.danger { color: var(--err); }
.btn.ok, button.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.small, button.small { padding: 4px 9px; font-size: 13px; }
.btn.block { display: block; }
button.link { background: none; border: none; color: var(--primary); font-weight: 500; }
form.inline { display: inline; }

table.list { width: 100%; border-collapse: collapse; background: #fff; }
table.list th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line); background: #fafbfc; }
table.list td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list tr:last-child td { border-bottom: none; }
table.list tr:hover td { background: #fafbfc; }
.r { text-align: right; white-space: nowrap; }
.table-wrap { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; overflow-x: auto; }

.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: #eef1f5; color: var(--muted); }
.badge.draft { background: #eef1f5; color: #57606a; }
.badge.final { background: #ddf4ff; color: #0550ae; }
.badge.paid { background: #dafbe1; color: var(--ok); }
.badge.cancelled { background: #ffebe9; color: var(--err); }
.badge.overdue { background: #fff1e5; color: #bc4c00; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; border: 1px solid; }
.flash.success { background: #dafbe1; border-color: #aceebb; color: #116329; }
.flash.error { background: #ffebe9; border-color: #ffcecb; color: #a40e26; }
.flash.warning { background: #fff8c5; border-color: #f2e08a; color: #7d4e00; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stat .v { font-size: 22px; font-weight: 700; margin-top: 4px; }
.stat .k { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }

/* Rechnungseditor */
table.lines { width: 100%; border-collapse: collapse; }
table.lines th { font-size: 12px; color: var(--muted); text-align: left; padding: 6px 4px; }
table.lines td { padding: 4px; vertical-align: top; }
table.lines input, table.lines select, table.lines textarea { padding: 6px 7px; }
table.lines textarea { min-height: 34px; height: 34px; margin-top: 4px; font-size: 13px; }
table.lines .num { text-align: right; }
table.lines .line-net { padding-top: 10px; font-weight: 600; }
.totals { margin-left: auto; width: 340px; }
.totals div { display: flex; justify-content: space-between; padding: 4px 0; }
.totals .grand { font-weight: 700; font-size: 16px; border-top: 2px solid var(--text); margin-top: 6px; padding-top: 8px; }
.checks ul { margin: 6px 0 0; padding-left: 20px; }
.checks .ok { color: var(--ok); font-weight: 600; }
.checks .bad { color: var(--err); font-weight: 600; }

dl.kv { display: grid; grid-template-columns: 170px 1fr; gap: 6px 12px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }
.pdf-frame { width: 100%; height: 900px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }

/* Auth-Seiten */
body.auth { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, #111827, #1f3a6e); }
.auth-box { background: #fff; padding: 32px; border-radius: 14px; width: 100%; max-width: 420px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.auth-box .logo { font-size: 28px; font-weight: 800; margin-bottom: 4px; }
.auth-box .logo span { color: var(--primary); }
.auth-box form > div { margin-bottom: 12px; }

@media (max-width: 900px) {
  body.app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .content { padding: 18px; }
  .g2, .g3, .g4, .stats { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
}
details.inline-details { display: inline-block; vertical-align: top; }
details.inline-details > summary { list-style: none; cursor: pointer; }
details.inline-details > summary::-webkit-details-marker { display: none; }
.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px; background: #f0f3f7; color: #57606a; margin: 1px 0; white-space: nowrap; }
table.taxcal tr.soon td:first-child { box-shadow: inset 3px 0 0 #bc4c00; }

/* Auswertungen */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs a { padding: 8px 14px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--text); border-bottom-color: var(--primary); }
.tabs a:hover { text-decoration: none; color: var(--text); }
.barchart { display: flex; gap: 6px; align-items: stretch; height: 200px; padding-top: 8px; }
.bar-col { flex: 1; display: flex; flex-direction: column; min-width: 0; cursor: default; }
.bar-col:hover .bar { background: var(--primary-d); }
.bar-col:hover .bar-label { color: var(--text); }
.bar-track { flex: 1; display: flex; align-items: flex-end; border-bottom: 1px solid var(--line); }
.bar { width: 100%; max-width: 44px; margin: 0 auto; background: var(--primary); border-radius: 4px 4px 0 0; min-height: 0; }
.bar-label { text-align: center; font-size: 12px; color: var(--muted); padding-top: 4px; }
