:root {
  color-scheme: light dark;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e8ef;
  --text: #1b2430;
  --muted: #667085;
  --brand: #1f7a5c;
  --brand-soft: #e3f4ed;
  --brand-ink: #0f5a42;
  --side: #14201c;
  --side-text: #b8c7c0;
  --side-active: #1f7a5c;
  --ok: #1f7a5c;
  --ok-soft: #e3f4ed;
  --warn: #b25e09;
  --warn-soft: #fdf0dc;
  --bad: #b42318;
  --bad-soft: #fde8e6;
  --info: #175cd3;
  --info-soft: #e5eefc;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1613;
    --surface: #17211d;
    --surface-2: #1c2823;
    --border: #2a3832;
    --text: #e8efeb;
    --muted: #93a39b;
    --brand: #3bb88d;
    --brand-soft: #173a2e;
    --brand-ink: #7fe0bc;
    --side: #0a100d;
    --side-text: #8fa399;
    --side-active: #1f7a5c;
    --ok: #4cc79b;
    --ok-soft: #173a2e;
    --warn: #f0b157;
    --warn-soft: #3a2a10;
    --bad: #f58f86;
    --bad-soft: #3d1a17;
    --info: #7aa8f5;
    --info-soft: #14284a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14.5px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.55rem; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Layout */
.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--side);
  color: var(--side-text);
  padding: 20px 14px;
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; color: #fff; font-weight: 700; font-size: 1.15rem; }
.brand-mark { width: 30px; height: 30px; border-radius: 9px; background: var(--side-active); display: grid; place-items: center; font-size: 1rem; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 9px;
  color: var(--side-text); font-weight: 500; text-decoration: none;
}
.nav a svg { width: 18px; height: 18px; flex: none; }
.nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav a.active { background: var(--side-active); color: #fff; }
.nav .count { margin-left: auto; background: var(--warn); color: #fff; border-radius: 99px; padding: 0 8px; font-size: .75rem; line-height: 1.5; }
.side-foot { margin-top: auto; font-size: .78rem; padding: 10px 12px; }
.side-note { opacity: .7; }
.lang-switch { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.lang-switch a { color: var(--side-text); opacity: .7; font-weight: 600; padding: 1px 6px; border-radius: 6px; text-decoration: none; }
.lang-switch a:hover { opacity: 1; color: #fff; }
.lang-switch a.active { background: var(--side-active); color: #fff; opacity: 1; }
.lang-switch .sep { opacity: .4; }

.main { padding: 28px 34px 60px; max-width: 1280px; width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head p { margin: 2px 0 0; color: var(--muted); }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.card + .card { margin-top: 18px; }
.grid { display: grid; gap: 16px; }
.grid.kpis { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin-bottom: 20px; }
.grid.two { grid-template-columns: 1.4fr 1fr; }
.grid.two-eq { grid-template-columns: 1fr 1fr; }
.kpi { padding: 16px 18px; }
.kpi .label { color: var(--muted); font-size: .82rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 1.7rem; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--muted); font-size: .82rem; }
.kpi.warn .value { color: var(--warn); }
.kpi.good .value { color: var(--ok); }

/* Tabellen */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 8px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.link:hover { background: var(--surface-2); cursor: pointer; }
th.num, td.num { text-align: right; }
.empty { padding: 36px 12px; text-align: center; color: var(--muted); }

/* Badges / Buttons / Forms */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 99px; font-size: .78rem; font-weight: 600; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.btn { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 8px 14px; border-radius: 9px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { padding: 4px 10px; font-size: .82rem; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .55; cursor: wait; }

.status-select { width: auto; padding: 3px 26px 3px 10px; border-radius: 99px; font-size: .8rem; font-weight: 600; cursor: pointer; border: 1px solid var(--border); }
.status-select.tone-info { background-color: var(--info-soft); color: var(--info); border-color: transparent; }
.status-select.tone-warn { background-color: var(--warn-soft); color: var(--warn); border-color: transparent; }
.status-select.tone-ok { background-color: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pay { white-space: nowrap; cursor: pointer; border: 1px solid var(--border); background: var(--surface-2); color: var(--muted); border-radius: 99px; padding: 3px 11px; font: inherit; font-size: .78rem; font-weight: 600; display: inline-flex; gap: 6px; align-items: center; }
.pay.partial { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pay.paid { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pay.na { opacity: .5; }
.pay:hover { filter: brightness(.97); }

label { display: block; font-size: .82rem; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=search], input[type=date], input[type=number], input[type=email], input[type=password], select, textarea {
  width: 100%; padding: 8px 11px; border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { resize: vertical; min-height: 90px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; align-items: end; }
.toolbar > div { min-width: 150px; }
.toolbar .grow { flex: 1; min-width: 200px; }
.actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }

.dropzone { border: 2px dashed var(--border); border-radius: 12px; padding: 18px; text-align: center; color: var(--muted); background: var(--surface-2); cursor: pointer; }
.dropzone.over { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-ink); }
.dropzone input { display: none; }

/* Flash */
.flashes { position: fixed; top: 16px; right: 16px; display: grid; gap: 8px; z-index: 50; max-width: 420px; }
.flash { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--info); padding: 10px 14px; border-radius: 9px; box-shadow: 0 6px 20px rgba(16,24,40,.15); }
.flash.success { border-left-color: var(--ok); }
.flash.error { border-left-color: var(--bad); }

/* Dialog */
dialog { border: 0; border-radius: 14px; padding: 0; width: min(640px, 94vw); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(10, 16, 13, .55); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 22px; border-bottom: 1px solid var(--border); }
.dlg-body { padding: 18px 22px 22px; }

/* Pipeline / Balken */
.bar-row { display: grid; grid-template-columns: 150px 1fr 36px; gap: 12px; align-items: center; margin: 9px 0; }
.bar { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; border: 1px solid var(--border); }
.bar > span { display: block; height: 100%; background: var(--brand); border-radius: 99px; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 10px 0; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.list li:last-child { border-bottom: 0; }

.mail { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; background: var(--surface); }
.mail.aus { border-left: 4px solid var(--info); }
.mail.ein { border-left: 4px solid var(--ok); }
.mail-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.mail pre { white-space: pre-wrap; font: inherit; margin: 8px 0 0; max-height: 160px; overflow: auto; color: var(--muted); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.chip { cursor: pointer; }
.tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.tabs a { padding: 6px 14px; border-radius: 99px; color: var(--muted); font-weight: 600; text-decoration: none; }
.tabs a.active { background: var(--brand-soft); color: var(--brand-ink); }
.pay-card { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.pay-box { border: 1px solid var(--border); border-radius: 11px; padding: 14px; background: var(--surface-2); }
.pay-box .amount { font-size: 1.3rem; font-weight: 700; margin: 4px 0 8px; font-variant-numeric: tabular-nums; }
.pay-list li { align-items: center; padding: 6px 0; }
.pay-list form { margin: 0; }
.pay-partial { margin-top: 10px; }
.pay-partial summary { cursor: pointer; color: var(--muted); font-weight: 600; font-size: .85rem; }
.pay-full { margin: 0 0 12px; }
.pay-form { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.pay-form input[name=notiz] { flex: 1; min-width: 120px; }
.pay-box.paid { background: var(--ok-soft); border-color: transparent; }
pre.out { white-space: pre-wrap; font: inherit; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px; min-height: 220px; }

.shell > * { min-width: 0; }

@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; flex-direction: column; align-items: stretch; padding: 10px; gap: 0; }
  .brand { padding: 0 8px 8px 4px; }
  .nav { display: flex; flex-wrap: nowrap; gap: 2px; overflow-x: auto; }
  .nav a { padding: 7px 10px; white-space: nowrap; }
  .nav a svg { display: none; }
  .grid.kpis { grid-template-columns: 1fr 1fr; }
  .page-head .btn { width: 100%; justify-content: center; }
  .side-note { display: none; }
  .side-foot { padding: 6px 8px 0; }
  .lang-switch { margin-bottom: 0; }
  .main { padding: 18px 16px 50px; }
  .grid.two, .grid.two-eq, .form-grid, .pay-card { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 110px 1fr 30px; }
}

.demo-banner { position: sticky; top: 0; z-index: 70; background: #b25e09; color: #fff; text-align: center; padding: 7px 14px; font-weight: 600; font-size: .88rem; }
.demo-banner a { color: #fff; text-decoration: underline; margin-left: 10px; }
