:root {
  --bg: #f5f6f3; --surface: #ffffff; --surface-2: #eef1ec; --line: #d9ded6; --text: #1d231d;
  --muted: #5f6b60; --accent: #2f7d4f; --accent-ink: #ffffff; --accent-soft: #e3f1e8;
  --warn: #8a5a00; --warn-soft: #fbf0d9; --danger: #b42318; --danger-soft: #fde8e6;
  --info: #1d5fa8; --info-soft: #e3eefa; --ok: #1f7a43; --ok-soft: #e1f3e8;
  --computed: #eceff2; --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131714; --surface: #1b211c; --surface-2: #232b24; --line: #313b33; --text: #e6ebe5;
    --muted: #9aa79b; --accent: #5cb27f; --accent-ink: #0d1a12; --accent-soft: #1f3327;
    --warn: #e7b85a; --warn-soft: #3a2f17; --danger: #f08a7e; --danger-soft: #3d1f1b;
    --info: #8bb8ec; --info-soft: #1c2b3d; --ok: #7fd3a0; --ok-soft: #1b3324; --computed: #262d27;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text); background: var(--bg); min-height: 100vh; display: flex; flex-direction: column; }
a { color: var(--accent); }
h1 { font-size: 1.55rem; margin: .2rem 0 1rem; line-height: 1.25; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
p { margin: 0 0 .75rem; }
code { font-size: .9em; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }

/* top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 18px; background: var(--accent); color: var(--accent-ink); position: sticky; top: 0; z-index: 10; }
.brand { display: flex; align-items: baseline; gap: 8px; color: inherit; text-decoration: none; font-weight: 700; font-size: 1.15rem; min-width: 0; }
.brand small { font-weight: 400; font-size: .78rem; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-mark { font-size: 1.1rem; }
.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 8px; background: rgba(255,255,255,.14); font-size: .9rem; }
.menu summary::-webkit-details-marker { display: none; }
.menu-icon, .menu-icon::before, .menu-icon::after { display: block; width: 16px; height: 2px; background: currentColor; border-radius: 2px; position: relative; }
.menu-icon::before, .menu-icon::after { content: ""; position: absolute; left: 0; }
.menu-icon::before { top: -5px; } .menu-icon::after { top: 5px; }
.menu nav { position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.15); min-width: 220px; padding: 6px; display: flex; flex-direction: column; }
.menu nav a, .menu nav .linklike { padding: 9px 12px; border-radius: 7px; color: var(--text); text-decoration: none; text-align: left; font: inherit; }
.menu nav a:hover, .menu nav .linklike:hover { background: var(--surface-2); }
.menu nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.logout { margin: 4px 0 0; border-top: 1px solid var(--line); padding-top: 4px; }
.mainnav { display: none; }
@media (min-width: 900px) {
  .menu { display: none; }
  .mainnav { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; justify-content: flex-end; }
  .mainnav a, .mainnav .linklike { color: var(--accent-ink); padding: 6px 10px; border-radius: 7px; text-decoration: none; font: inherit; font-size: .92rem; }
  .mainnav a:hover, .mainnav .linklike:hover { background: rgba(255,255,255,.16); }
  .mainnav a.active { background: rgba(255,255,255,.22); font-weight: 600; }
  .mainnav .logout { margin: 0 0 0 6px; border: 0; padding: 0; }
}
.linklike { background: none; border: 0; cursor: pointer; padding: 0; color: inherit; width: 100%; }

main { width: 100%; max-width: 1080px; margin: 0 auto; padding: 18px 16px 40px; flex: 1; }
main.wide { max-width: 1280px; }
.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 16px; }
.crumbs { font-size: .85rem; color: var(--muted); margin-bottom: 6px; display: flex; flex-wrap: wrap; gap: 4px; }
.crumbs a { color: var(--muted); }
.crumbs .sep { opacity: .6; }

/* surfaces */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card > h2:first-child, .card > header:first-child { margin-top: 0; }
.card header { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.card header h2 { margin: 0; }
.grid-2 { display: grid; gap: 16px; grid-template-columns: 1fr; }
.grid-3 { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 760px) { .grid-2 { grid-template-columns: 1fr 1fr; } .grid-3 { grid-template-columns: repeat(3, 1fr); } }
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); margin-bottom: 16px; }
.tile { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; text-decoration: none; color: var(--text); box-shadow: var(--shadow); }
.tile:hover { border-color: var(--accent); }
.tile .t-title { font-weight: 650; font-size: 1.02rem; }
.tile .t-sub { color: var(--muted); font-size: .86rem; }
.stat { font-size: 1.6rem; font-weight: 700; }
.pagehead { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.pagehead h1 { margin-bottom: .25rem; }
.sub { color: var(--muted); margin: 0 0 1rem; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.empty { color: var(--muted); padding: 10px 0; }
.empty p { margin: 0 0 8px; }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; overflow-wrap: anywhere; }

/* tables */
.tablewrap { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }
table.list { border-collapse: collapse; width: 100%; font-size: .93rem; }
table.list th { text-align: left; font-weight: 600; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .02em; padding: 6px 8px; border-bottom: 2px solid var(--line); white-space: nowrap; }
table.list td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list tr:last-child td { border-bottom: 0; }
table.list td.num, table.list th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.list a { font-weight: 550; }

/* badges, flash */
.badge { display: inline-block; font-size: .74rem; font-weight: 650; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-muted { background: var(--surface-2); color: var(--muted); }
.badge-role { background: var(--accent-soft); color: var(--accent); }
.flash { padding: 10px 14px; border-radius: 8px; margin: 0 0 14px; border: 1px solid transparent; }
.flash-ok { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.flash-error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.flash-info { background: var(--info-soft); color: var(--info); }

/* forms */
form.stack { display: flex; flex-direction: column; gap: 12px; }
.fields { display: grid; gap: 12px 16px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.field { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; }
.field .lbl { color: var(--muted); font-weight: 550; }
.field .hint { color: var(--muted); font-size: .8rem; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 0; border-color: var(--accent); }
input[type=checkbox], input[type=radio] { width: auto; }
.check { display: flex; align-items: center; gap: 8px; font-size: .92rem; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; font-size: .92rem; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:hover { filter: brightness(1.05); }
.btn-secondary { background: var(--surface); color: var(--accent); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn-danger { background: var(--surface); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.btn-small { padding: 4px 10px; font-size: .84rem; }
.btn[disabled] { opacity: .55; cursor: default; }
form.inline { display: inline; margin: 0; }

/* auth screens */
.auth { max-width: 440px; margin: 4vh auto 0; }
.auth .card { padding: 22px 24px; }
.auth h1 { font-size: 1.35rem; }
.code-input { font-size: 1.5rem; letter-spacing: .4em; text-align: center; font-variant-numeric: tabular-nums; }

/* misc */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.notes { list-style: none; padding: 0; margin: 0; }
.notes li { border-left: 3px solid var(--line); padding: 4px 0 4px 12px; margin-bottom: 12px; }
.notes li.intern { border-left-color: var(--warn); }
.notes .meta { color: var(--muted); font-size: .8rem; }
.notes .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.toolbar input, .toolbar select { width: auto; }
.versions { list-style: none; padding: 0; margin: 0; }
.versions li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.versions li:last-child { border: 0; }
.versions li.current { font-weight: 600; }
.diff { width: 100%; border-collapse: collapse; font-size: .88rem; }
.diff td, .diff th { padding: 4px 6px; border-bottom: 1px solid var(--line); vertical-align: top; text-align: left; }
.diff .before { color: var(--danger); text-decoration: line-through; }
.diff .after { color: var(--ok); }
details.more > summary { cursor: pointer; color: var(--accent); font-weight: 600; margin-bottom: 8px; }
.savebar { position: sticky; bottom: 0; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(6px); border-top: 1px solid var(--line); padding: 10px 0; margin-top: 12px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; z-index: 5; }
.savebar .status { color: var(--muted); font-size: .85rem; margin-right: auto; }

/* ---------- document form (renderer) ---------- */
.docform .screen-info h2 { margin-bottom: 2px; }
.docform .desc { color: var(--muted); font-size: .86rem; background: var(--surface); border-left: 3px solid var(--accent); padding: 8px 12px; margin: 0 0 14px; }
.docform fieldset { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin: 0 0 14px; padding: 10px 14px 14px; min-width: 0; }
.docform legend { font-weight: 650; padding: 0 6px; }
.docform .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px 16px; }
.docform .field { font-size: .86rem; }
.docform input, .docform select, .docform textarea { padding: 6px 8px; }
.docform input.computed, .docform .computed { background: var(--computed); font-weight: 650; }
.docform .field.checkbox { flex-direction: row; align-items: center; gap: 8px; }
.docform .euro { position: relative; display: block; }
.docform .euro > input { padding-right: 22px; }
.docform .euro::after { content: "€"; position: absolute; right: 8px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 12px; pointer-events: none; }
.docform table { border-collapse: collapse; width: 100%; font-size: .86rem; }
.docform .tablewrap { overflow-x: auto; }
.docform th { text-align: left; font-weight: 600; color: var(--muted); padding: 4px 6px; border-bottom: 2px solid var(--line); font-size: .78rem; }
.docform td { padding: 3px 4px; border-bottom: 1px solid var(--surface-2); }
.docform td input, .docform td select { min-width: 80px; }
.docform .totals { display: flex; flex-wrap: wrap; gap: 8px 18px; justify-content: flex-end; margin-top: 8px; font-size: .88rem; }
.docform .totals output { font-weight: 700; background: var(--computed); padding: 2px 8px; border-radius: 6px; }
.docform button.add { margin-top: 8px; }
.docform button.del { background: var(--surface); border: 1px solid var(--line); color: var(--danger); border-radius: 6px; cursor: pointer; width: 30px; height: 30px; }
.docform .tabs { display: flex; flex-wrap: wrap; gap: 4px; margin: 0 0 14px; border-bottom: 2px solid var(--line); }
.docform .tab { padding: 7px 12px; border: 1px solid var(--line); border-bottom: 0; border-radius: 7px 7px 0 0; background: var(--surface-2); color: var(--muted); cursor: pointer; font: inherit; font-size: .84rem; }
.docform .tab.active { background: var(--surface); color: var(--accent); font-weight: 650; }
.docform .page { display: none; }
.docform .page.active { display: block; }
.docform .page-title { font-size: 1rem; margin: 0 0 10px; color: var(--accent); }
.docform .note { font-size: .86rem; margin: 0 0 8px; }
.docform .reftable { border-collapse: collapse; margin: 0 0 12px; width: auto; }
.docform .reftable th, .docform .reftable td { border: 1px solid var(--line); padding: 4px 10px; }
.docform .reftable th { background: var(--surface-2); }
.docform .gridtable td.merkmal { font-weight: 600; white-space: nowrap; }
.docform .print-header { display: none; }
.docform.readonly input, .docform.readonly select, .docform.readonly textarea { background: transparent; border-color: transparent; border-bottom-color: var(--line); border-radius: 0; color: var(--text); opacity: 1; -webkit-text-fill-color: var(--text); }
.docform.readonly input.computed { background: var(--computed); border-radius: 6px; }
.docform.readonly select { appearance: none; -webkit-appearance: none; }

@media print {
  @page { size: A4; margin: 16mm 14mm; }
  :root { --bg: #fff; --surface: #fff; --line: #bbb; --text: #000; --muted: #444; --computed: #eceff2; }
  body { background: #fff; font-size: 11px; display: block; }
  .topbar, .crumbs, .foot, .no-print, .savebar, .flash, .docform .tabs, .docform button.add, .docform button.del, .docform .screen-info { display: none !important; }
  main { max-width: none; padding: 0; margin: 0; }
  .card { border: 0; padding: 0; box-shadow: none; }
  .docform .rowtable td:last-child, .docform .rowtable th:last-child { display: none !important; }
  .docform.readonly .rowtable td:last-child, .docform.readonly .rowtable th:last-child { display: table-cell !important; }
  .docform .page { display: block !important; break-before: page; }
  .docform .page:first-of-type { break-before: avoid; }
  .docform fieldset { border: 1px solid #bbb; border-radius: 0; margin: 0 0 8px; padding: 6px 10px 10px; break-inside: avoid; }
  .docform .print-header { display: flex; justify-content: space-between; align-items: baseline; border-bottom: 2px solid #14532d; padding-bottom: 4px; margin-bottom: 10px; }
  .docform .print-header span { color: #444; font-size: 10px; }
  .docform input, .docform select, .docform textarea { border: 0; border-bottom: 1px solid #999; border-radius: 0; padding: 1px 2px; background: transparent; appearance: none; -webkit-appearance: none; color: #000; font-size: 10px; }
  .docform input.computed, .docform .computed, .docform .totals output { background: #eceff2 !important; font-weight: 700; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .docform input[type=checkbox] { appearance: auto; -webkit-appearance: auto; width: 12px; height: 12px; }
  .docform th { font-size: 9px; border-bottom: 1px solid #333; }
  .docform .field { font-size: 10px; }
}
