:root {
  color-scheme: light;
  --bg: #eef1f0;
  --surface: #ffffff;
  --ink: #17212a;
  --muted: #5d6a72;
  --line: #d8dedc;
  --accent: #1f5fae;
  --accent-ink: #ffffff;
  --ok: #2b7a55;
  --warn: #9c6410;
  --bad: #b03636;
  --rail-review: #d9a441;
  --rail-ok: #3c9a6c;
  --rail-bad: #c46a6a;
  --radius: 10px;
  --font: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #121719;
    --surface: #1a2125;
    --ink: #e5ebee;
    --muted: #93a1a8;
    --line: #2b353b;
    --accent: #78a9ec;
    --accent-ink: #0d1a2b;
    --ok: #6cc59a;
    --warn: #e0b060;
    --bad: #ec8b8b;
    --rail-review: #b98a2f;
    --rail-ok: #3f8f67;
    --rail-bad: #a35757;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 400 15px/1.5 var(--font);
  font-feature-settings: "tnum" 0;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, h3 { font-weight: 600; margin: 0; letter-spacing: -0.01em; }

/* Bedienelemente ------------------------------------------------------- */
.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  padding: 10px 16px;
  cursor: pointer;
  font-weight: 500;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.small { padding: 6px 12px; font-size: 14px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; }

input[type=search], input[type=text], input[type=email], input[type=password],
input[type=date], input[type=url], input[type=number], select, textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
}
textarea { min-height: 90px; resize: vertical; }
.field { display: grid; gap: 4px; }
.field > span { font-size: 13px; color: var(--muted); }
.error { color: var(--bad); margin: 0; }
.hint { color: var(--muted); font-size: 14px; margin: 4px 0 0; }

/* Anmeldung ------------------------------------------------------------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(380px, 100%);
  display: grid;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px;
}
.login-title { font-size: 28px; }
.login-sub { margin: -12px 0 4px; color: var(--muted); }

/* Grundlayout: mobil Tableiste unten, ab 960px Seitenleiste ----------- */
.app { min-height: 100%; }
.main { padding: 0 16px calc(84px + env(safe-area-inset-bottom)); max-width: 1100px; }
.nav {
  position: fixed; inset: auto 0 0 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.brand, .nav-foot { display: none; }
.tab {
  position: relative;
  display: grid; justify-items: center; gap: 2px;
  background: none; border: 0; padding: 9px 4px 8px;
  color: var(--muted); font-size: 12px; cursor: pointer;
}
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.tab[aria-current=page] { color: var(--accent); font-weight: 600; }
.badge {
  position: absolute; top: 4px; left: calc(50% + 6px);
  min-width: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--rail-review); color: #1d1406;
  font-size: 11px; line-height: 18px; font-weight: 600; text-align: center;
}

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) 0 12px;
  background: var(--bg);
}
.topbar h2 { font-size: 24px; }
.scan { display: flex; align-items: center; gap: 10px; min-width: 0; }
.scan-text { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scan-text.busy::before {
  content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 6px;
  border-radius: 50%; background: var(--accent); animation: pulse 1.2s infinite;
}
@keyframes pulse { 50% { opacity: .25; } }

@media (min-width: 960px) {
  .app { display: grid; grid-template-columns: 220px minmax(0, 1fr); }
  .nav {
    position: sticky; top: 0; height: 100vh;
    display: flex; flex-direction: column; gap: 2px;
    border-top: 0; border-right: 1px solid var(--line);
    padding: 22px 12px;
  }
  .brand { display: block; font-weight: 600; font-size: 19px; padding: 0 12px 20px; }
  .brand span { display: block; font-weight: 400; font-size: 13px; color: var(--muted); }
  .tab {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; border-radius: 8px; font-size: 15px;
  }
  .tab[aria-current=page] { background: var(--bg); }
  .badge { position: static; margin-left: auto; }
  .nav-foot {
    display: grid; gap: 4px; margin-top: auto; padding: 12px;
    font-size: 14px; color: var(--muted);
  }
  .nav-foot .link { justify-self: start; }
  .main { padding: 0 32px 40px; }
}

/* Filter ------------------------------------------------------------------ */
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.filters input[type=search] { grid-column: 1 / -1; }
.date { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
@media (min-width: 700px) {
  .filters { grid-template-columns: 1fr auto auto; }
  .filters input[type=search] { grid-column: auto; }
}

/* Umschalter Zu prüfen / Aussortiert */
.segments { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 3px; margin-bottom: 12px; }
.segment { background: none; border: 0; border-radius: 6px; padding: 6px 14px; cursor: pointer; color: var(--muted); font-weight: 500; }
.segment[aria-selected=true] { background: var(--bg); color: var(--ink); }
.segment b { font-weight: 500; margin-left: 6px; color: var(--muted); }
.tag.auto { border-color: var(--accent); color: var(--accent); }
.tag.busy { border-style: dashed; }
.tag.err { border-color: var(--bad); color: var(--bad); }
.settings .row-inline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* Kontobuch-Liste: das prägende Element ------------------------------------
   Links eine farbige Statuskante, rechts groß der Betrag in Tabellenziffern. */
.ledger { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.ledger:empty { display: none; }
.row {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 16px;
  padding: 12px 16px 12px 18px;
  border-bottom: 1px solid var(--line);
  cursor: pointer; position: relative;
}
.row:last-child { border-bottom: 0; }
.row::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--rail-ok); }
.row.review::before { background: var(--rail-review); }
.row.rejected::before { background: var(--rail-bad); }
.row:hover { background: color-mix(in srgb, var(--bg) 60%, var(--surface)); }
.row.active { background: var(--bg); }
.row-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta { grid-column: 1; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-reason { grid-column: 1 / -1; color: var(--muted); font-size: 13px; }
.amount {
  grid-row: 1 / span 2; grid-column: 2; align-self: center; text-align: right;
  font-size: 18px; font-weight: 600; font-feature-settings: "tnum" 1;
  white-space: nowrap;
}
.amount.none { color: var(--muted); font-weight: 400; font-size: 14px; }
.tag { display: inline-block; font-size: 12px; padding: 0 7px; border-radius: 4px; border: 1px solid var(--line); color: var(--muted); margin-left: 6px; vertical-align: 1px; }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.empty strong { display: block; color: var(--ink); font-size: 17px; margin-bottom: 4px; }
.more { display: block; margin: 14px auto 0; }

/* Erfassen ---------------------------------------------------------------- */
.capture { display: grid; gap: 12px; }
.capture-main, .capture-files {
  display: grid; justify-items: center; gap: 4px; text-align: center;
  border-radius: var(--radius); padding: 28px 16px; cursor: pointer;
}
.capture-main { background: var(--accent); color: var(--accent-ink); }
.capture-main svg { width: 40px; height: 40px; fill: none; stroke: currentColor; stroke-width: 1.5; }
.capture-main strong { font-size: 19px; }
.capture-main span { opacity: .85; font-size: 14px; }
.capture-files { border: 1.5px dashed var(--line); background: var(--surface); }
.capture-files span { color: var(--muted); font-size: 14px; }
.capture-files.over { border-color: var(--accent); }
@media (min-width: 700px) { .capture { grid-template-columns: 1fr 1fr; } }
.uploads { list-style: none; padding: 0; margin: 16px 0 0; display: grid; gap: 8px; }
.upload { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; }
.upload progress { grid-column: 1 / -1; width: 100%; height: 4px; accent-color: var(--accent); }
.upload .state { font-size: 13px; color: var(--muted); }
.upload .state.ok { color: var(--ok); }
.upload .state.bad { color: var(--bad); }

/* Detailansicht: mobil Vollbild, Desktop rechte Spalte ------------------ */
.detail {
  position: fixed; inset: 0; z-index: 30; overflow-y: auto;
  background: var(--bg);
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
.detail-head { position: sticky; top: 0; background: var(--bg); padding: 12px 16px; z-index: 1; }
.detail-body { padding: 0 16px 40px; display: grid; gap: 18px; max-width: 760px; }
@media (min-width: 1280px) {
  .app.with-detail { grid-template-columns: 220px minmax(0, 1fr) minmax(420px, 40%); }
  .detail { position: sticky; top: 0; height: 100vh; border-left: 1px solid var(--line); }
  .detail-head .btn::after { content: ""; }
}
.d-top { display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; align-items: end; }
.d-top h3 { font-size: 22px; overflow-wrap: anywhere; }
.d-amount { font-size: 26px; font-weight: 600; font-feature-settings: "tnum" 1; text-align: right; }
.d-sub { grid-column: 1 / -1; color: var(--muted); font-size: 14px; }
.status { display: inline-block; font-size: 13px; font-weight: 500; padding: 2px 9px; border-radius: 999px; }
.status.review { background: color-mix(in srgb, var(--rail-review) 22%, transparent); color: var(--warn); }
.status.confirmed { background: color-mix(in srgb, var(--rail-ok) 20%, transparent); color: var(--ok); }
.status.rejected { background: color-mix(in srgb, var(--rail-bad) 20%, transparent); color: var(--bad); }
.reason { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--rail-review); border-radius: 8px; padding: 10px 14px; font-size: 14px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.preview { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.preview iframe { width: 100%; height: 70vh; border: 0; display: block; background: #fff; }
.preview img { width: 100%; display: block; }
.preview .doc-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 12px; border-top: 1px solid var(--line); font-size: 14px; }
.preview .doc-msg { padding: 24px; text-align: center; color: var(--muted); }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form .full { grid-column: 1 / -1; }
.form .num input { text-align: right; font-feature-settings: "tnum" 1; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.block { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 8px; }
.block h4 { margin: 0; font-size: 15px; font-weight: 600; }
.mailtext { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; max-height: 320px; overflow-y: auto; color: var(--muted); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

/* Einstellungen ---------------------------------------------------------- */
.settings { display: grid; gap: 28px; }
.settings section { display: grid; gap: 12px; }
.settings h3 { font-size: 18px; }
.settings .intro { color: var(--muted); margin: -6px 0 0; font-size: 14px; max-width: 70ch; }
.provider { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 10px; }
.provider-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.provider-head strong { font-size: 16px; }
.pill { font-size: 12px; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.pill.on { border-color: var(--ok); color: var(--ok); }
.pill.off { border-color: var(--bad); color: var(--bad); }
.task { display: grid; grid-template-columns: 1fr; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.task:last-child { border-bottom: 0; }
@media (min-width: 700px) { .task { grid-template-columns: 1.3fr 1fr 1fr; align-items: center; } }
.list-simple { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.list-simple li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.list-simple li:last-child { border-bottom: 0; }
.list-simple .sub { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.inline-form { display: grid; grid-template-columns: 1fr; gap: 8px; }
@media (min-width: 700px) { .inline-form { grid-template-columns: 1fr 2fr auto; } }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(92px + env(safe-area-inset-bottom)); z-index: 50;
  background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 8px; font-size: 14px; max-width: calc(100% - 32px);
}
@media (min-width: 960px) { .toast { bottom: 24px; } }

@media (prefers-reduced-motion: reduce) {
  .scan-text.busy::before { animation: none; }
}
