:root {
  --ink: #1a1a2e;
  --ink-2: #26264a;
  --paper: #f3f4f8;
  --surface: #ffffff;
  --text: #1d2330;
  --muted: #667085;
  --line: #e2e5ee;
  --ok: #1f7a5a;
  --ok-bg: #e5f4ee;
  --warn: #9a5b0b;
  --warn-bg: #fcf1df;
  --ki: #5645b0;
  --ki-bg: #eeebfb;
  --focus: #3b5bdb;
  --radius-s: 6px;
  --radius-m: 10px;
  font-size: 15px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text); background: var(--paper); line-height: 1.5;
}
a { color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }
.r { text-align: right; }
.nowrap { white-space: nowrap; }

/* Layout */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--ink); color: #d9dbee; padding: 22px 14px; display: flex; flex-direction: column; gap: 26px; position: sticky; top: 0; height: 100vh; }
.brand { text-decoration: none; padding: 0 10px; display: block; }
.brand-name { font-weight: 600; font-size: 1.2rem; color: #fff; letter-spacing: -0.01em; }
.brand-sub { font-size: 0.8rem; color: #9ea2c7; }
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav a { text-decoration: none; padding: 9px 10px; border-radius: var(--radius-s); display: flex; justify-content: space-between; align-items: center; }
.side nav a:hover { background: var(--ink-2); color: #fff; }
.side nav a.on { background: #fff; color: var(--ink); font-weight: 500; }
.count { background: #f0b44c; color: var(--ink); font-size: 0.78rem; font-weight: 600; border-radius: 999px; padding: 1px 8px; min-width: 24px; text-align: center; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 0 10px; font-size: 0.86rem; }
.side .muted-link { color: #9ea2c7; }
.linkbtn { background: none; border: 0; color: #9ea2c7; padding: 0; font: inherit; cursor: pointer; text-decoration: underline; }
.main { padding: 28px 36px 60px; max-width: 1280px; width: 100%; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
h1 { font-size: 1.75rem; font-weight: 600; margin: 0; letter-spacing: -0.02em; }
h1 .id { color: var(--muted); font-weight: 400; font-size: 1.1rem; }
h2 { font-size: 1.02rem; font-weight: 600; margin: 0; }
.back { font-size: 0.85rem; color: var(--muted); text-decoration: none; display: inline-block; margin-bottom: 4px; }
.back::before { content: "‹ "; }
.head-tags { display: flex; gap: 8px; align-items: center; }

/* Buttons */
.btn { font: inherit; font-weight: 500; border: 1px solid var(--line); background: var(--surface); color: var(--text); padding: 8px 14px; border-radius: var(--radius-s); cursor: pointer; text-decoration: none; display: inline-block; }
.btn:hover { border-color: #c5cad8; }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.primary:hover { background: var(--ink-2); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 0.85rem; }
.btn.wide { width: 100%; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* Hinweise */
.flash, .notice { border-radius: var(--radius-s); padding: 10px 14px; margin-bottom: 14px; background: #eef1f7; border-left: 3px solid #9aa3ba; }
.flash.ok { background: var(--ok-bg); border-color: var(--ok); }
.flash.warn, .notice.warn { background: var(--warn-bg); border-color: #d8952b; }
.notice.ki { background: var(--ki-bg); border-color: var(--ki); }

/* Übersicht */
.todo { display: flex; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.todo-main { flex: 1 1 420px; display: flex; align-items: center; gap: 18px; background: var(--warn-bg); border: 1px solid #efd3a4; border-radius: var(--radius-m); padding: 18px 22px; text-decoration: none; }
.todo-main:hover { border-color: #d8952b; }
.todo-main.clear { background: var(--ok-bg); border-color: #bfe3d3; }
.todo-num { font-size: 2.6rem; font-weight: 600; line-height: 1; color: var(--warn); font-variant-numeric: tabular-nums; }
.todo-text { font-size: 1.05rem; font-weight: 500; }
.todo-side { flex: 0 1 300px; display: flex; align-items: center; padding: 14px 18px; border-radius: var(--radius-m); text-decoration: none; font-weight: 500; }
.todo-side.ki { background: var(--ki-bg); color: var(--ki); border: 1px solid #d6d0f5; }
.facts { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--line); border-radius: var(--radius-m); background: var(--surface); margin-bottom: 18px; }
.facts > div { padding: 14px 18px; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 2px; }
.facts > div:last-child { border-right: 0; }
.fact-label { font-size: 0.82rem; color: var(--muted); }
.fact-val { font-size: 1.3rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.fact-val.small { font-size: 1rem; font-weight: 500; }
.footnote { color: var(--muted); font-size: 0.85rem; margin-top: 18px; }

/* Panels und Tabellen */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); margin-bottom: 18px; overflow: hidden; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; padding: 14px 18px; border-bottom: 1px solid var(--line); gap: 12px; }
.panel-head a { font-size: 0.9rem; color: var(--muted); }
.panel-body { padding: 16px 18px; }
.panel-body p { margin: 0 0 10px; max-width: 75ch; }
.muted { color: var(--muted); }
.sum { color: var(--muted); }
.sum strong { color: var(--text); font-size: 1.05rem; }
.table-wrap { overflow-x: auto; }
table.docs { width: 100%; border-collapse: collapse; }
.docs th { text-align: left; font-weight: 500; font-size: 0.82rem; color: var(--muted); padding: 9px 18px; border-bottom: 1px solid var(--line); background: #fafbfd; }
.docs td { padding: 10px 18px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.docs tbody tr { cursor: pointer; }
.docs tbody tr:hover { background: #f7f8fc; }
.docs tbody tr:last-child td { border-bottom: 0; }
.docs td a { text-decoration: none; font-weight: 500; }
.docs th.r, .docs td.r { text-align: right; }
.gap { color: var(--warn); font-size: 0.85rem; font-style: italic; }
.empty { color: var(--muted); padding: 18px; margin: 0; }
.empty.big { font-size: 1.1rem; padding: 40px 0; }

.status, .src, .tag { font-size: 0.78rem; font-weight: 500; border-radius: 999px; padding: 2px 9px; white-space: nowrap; }
.s-erkannt { background: #edf0f6; color: #3d475c; }
.s-unklar { background: var(--warn-bg); color: var(--warn); }
.s-geprueft { background: var(--ok-bg); color: var(--ok); }
.s-ignoriert { background: #f0f0f0; color: #8a8a8a; }
.src { background: transparent; color: var(--muted); padding: 0; }
.src-ki { background: var(--ki-bg); color: var(--ki); padding: 2px 9px; }
.tag.credit { background: #e8f0fc; color: #2c55a0; margin-left: 6px; }

/* Filter */
.filters { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.filters input[type=search] { flex: 1 1 280px; }
input, select, textarea { font: inherit; color: var(--text); padding: 8px 10px; border: 1px solid #cfd4e0; border-radius: var(--radius-s); background: #fff; width: 100%; }
.filters select { width: auto; }
.reset { color: var(--muted); font-size: 0.9rem; }

/* Detail */
.detail { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(320px, 1fr); gap: 22px; align-items: start; }
.viewer { position: sticky; top: 20px; display: flex; flex-direction: column; gap: 8px; }
.viewer iframe { width: 100%; height: calc(100vh - 150px); min-height: 480px; border: 1px solid var(--line); border-radius: var(--radius-m); background: #fff; }
.viewer .muted-link { font-size: 0.85rem; color: var(--muted); }
.sheet { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 18px; }
.fields { display: flex; flex-direction: column; gap: 12px; }
.fields label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); }
.fields label input, .fields label select, .fields label textarea { font-size: 1rem; color: var(--text); }
.fields label.check { flex-direction: row; align-items: center; gap: 8px; margin-top: -6px; }
.fields label.check input { width: auto; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.side-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.meta { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 0.86rem; margin: 18px 0 0; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; overflow-wrap: anywhere; }
.hash { font-variant-numeric: tabular-nums; color: var(--muted); }
.history { margin-top: 16px; font-size: 0.85rem; }
.history summary { cursor: pointer; color: var(--muted); }
.history ul { padding-left: 18px; }
.history li span { color: var(--muted); }

/* Klärliste */
.rows { list-style: none; margin: 0; padding: 0; }
.rows li { display: flex; align-items: center; gap: 14px; padding: 11px 18px; border-bottom: 1px solid var(--line); }
.rows li:last-child { border-bottom: 0; }
.row-main { flex: 1; text-decoration: none; display: flex; flex-direction: column; min-width: 0; }
.row-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: 0.85rem; color: var(--muted); }
.row-miss { font-size: 0.85rem; color: var(--warn); white-space: nowrap; }
.panel-tool { display: flex; gap: 12px; align-items: center; padding: 12px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; font-size: 0.9rem; }
.summary-head { cursor: pointer; list-style: none; border-bottom: 0; }
.summary-head::-webkit-details-marker { display: none; }
details[open] .summary-head { border-bottom: 1px solid var(--line); }
.hint { color: var(--muted); font-size: 0.9rem; padding: 12px 18px 0; margin: 0; max-width: 80ch; }
.state.ok::before { content: "● "; color: var(--ok); }
.state.off::before { content: "● "; color: #b0b4c2; }

/* Login und Rechtstext */
.login-body { display: grid; place-items: center; min-height: 100vh; background: var(--ink); }
.login { background: var(--surface); padding: 30px; border-radius: var(--radius-m); width: min(360px, 92vw); display: flex; flex-direction: column; gap: 12px; }
.login .brand-name { color: var(--ink); }
.login .brand-sub { color: var(--muted); margin-top: -10px; margin-bottom: 8px; }
.login label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); }
.login .muted-link { font-size: 0.8rem; color: var(--muted); text-align: center; }
.legal-body { background: var(--surface); }
.legal { max-width: 68ch; margin: 0 auto; padding: 48px 22px; }
.legal h1 { margin-bottom: 18px; }
.legal h2 { margin-top: 26px; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 12px; padding: 12px 14px; }
  .side nav { flex-direction: row; flex-wrap: wrap; }
  .side-foot { display: none; }
  .main { padding: 18px 14px 40px; }
  .facts { grid-template-columns: 1fr 1fr; }
  .facts > div:nth-child(2) { border-right: 0; }
  .facts > div:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .detail { grid-template-columns: 1fr; }
  .viewer { position: static; }
  .viewer iframe { height: 60vh; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }

/* Abrechnungen */
.sub { margin: 2px 0 0; color: var(--muted); font-size: 0.88rem; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.fact-note { font-size: 0.8rem; color: var(--muted); }
.fact-val.ok { color: var(--ok); }
.fact-val.warn { color: var(--warn); }
.control { font-size: 0.85rem; margin: -8px 0 16px; color: var(--muted); }
.control.bad { color: #b42318; font-weight: 500; }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; flex-wrap: wrap; }
.tabs a { text-decoration: none; padding: 7px 12px; border-radius: var(--radius-s); color: var(--muted); font-weight: 500; }
.tabs a span { font-size: 0.8rem; margin-left: 4px; }
.tabs a.on { background: var(--surface); color: var(--text); border: 1px solid var(--line); }
.bar { width: 120px; height: 8px; border-radius: 999px; background: #eceef4; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--ok); }
.upload-inline { margin: 0; }
.txs { list-style: none; margin: 0; padding: 0; }
.tx { padding: 12px 18px; border-bottom: 1px solid var(--line); scroll-margin-top: 20px; }
.tx:last-child { border-bottom: 0; }
.tx:target { background: #f6f8ff; }
.tx-head { display: grid; grid-template-columns: 92px minmax(0, 1fr) 120px 130px; gap: 12px; align-items: baseline; }
.tx-date { color: var(--muted); font-variant-numeric: tabular-nums; }
.tx-desc { display: flex; flex-direction: column; min-width: 0; }
.tx-desc .muted { font-size: 0.8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-amt { text-align: right; font-weight: 600; }
.tx-amt.credit { color: var(--ok); }
.tx-body { margin-left: 104px; display: flex; flex-direction: column; gap: 6px; }
.tx-body:empty { display: none; }
.tx-hint { margin: 4px 0 0; font-size: 0.86rem; color: var(--muted); }
.tx-note { margin: 0; font-size: 0.86rem; color: var(--warn); white-space: pre-line; }
.match { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.match-doc { font-size: 0.9rem; }
.tx-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.tx-actions form, .match form { margin: 0; }
.tx-actions:empty { display: none; }
.tstatus { font-size: 0.78rem; font-weight: 500; border-radius: 999px; padding: 2px 9px; justify-self: start; white-space: nowrap; }
.t-offen { background: var(--warn-bg); color: var(--warn); }
.t-vorschlag, .t-mehrdeutig { background: #e8eefc; color: #2c4fa0; }
.t-zugeordnet { background: var(--ok-bg); color: var(--ok); }
.t-storno, .t-gutschrift, .t-kein_beleg, .t-papier, .t-zahlung { background: #eef0f4; color: #4a5263; }
.linked { margin: 16px 0 0; padding: 10px 12px; background: var(--ok-bg); border-radius: var(--radius-s); font-size: 0.88rem; }
@media (max-width: 900px) {
  .tx-head { grid-template-columns: 1fr auto; }
  .tx-date { grid-column: 1 / -1; }
  .tx-body { margin-left: 0; }
}
