/* =========================================================================
   Refundi – Oberfläche
   Aufbau: Tokens · Grundlagen · Layout · Komponenten · Seiten · Responsive
   ========================================================================= */

/* --- Tokens -------------------------------------------------------------- */
:root {
  --bg: #f4f6f9;
  --bg-grad: radial-gradient(1200px 600px at 15% -10%, #e8ecf5 0%, transparent 60%);
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --surface-3: #eef1f6;
  --text: #0f1419;
  --text-2: #3d4654;
  --muted: #6b7482;
  --border: #e2e7ee;
  --border-strong: #cdd5e0;

  --accent: #4f46e5;
  --accent-soft: #eef0fe;
  --accent-text: #4338ca;

  --ok: #0b7a53;
  --ok-soft: #e3f6ee;
  --warn: #a15c07;
  --warn-soft: #fdf2dd;
  --bad: #b42318;
  --bad-soft: #fdeceb;
  --info: #0b6bb3;
  --info-soft: #e6f2fb;

  --shadow-sm: 0 1px 2px rgba(15, 20, 25, .06), 0 1px 3px rgba(15, 20, 25, .04);
  --shadow: 0 4px 12px rgba(15, 20, 25, .07), 0 1px 3px rgba(15, 20, 25, .05);
  --shadow-lg: 0 16px 40px rgba(15, 20, 25, .14);

  --r-sm: 6px;
  --r: 10px;
  --r-lg: 14px;
  --r-xl: 20px;

  --sidebar-w: 232px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}

:root[data-theme="dark"],
html.dark {
  --bg: #0d1015;
  --bg-grad: radial-gradient(1200px 600px at 15% -10%, #182033 0%, transparent 60%);
  --surface: #151a21;
  --surface-2: #1b212a;
  --surface-3: #232b36;
  --text: #e9edf2;
  --text-2: #c2cad6;
  --muted: #8b94a3;
  --border: #262e3a;
  --border-strong: #38424f;

  --accent: #7c7cf5;
  --accent-soft: #1e2145;
  --accent-text: #a9a9fb;

  --ok: #3ecf8e;
  --ok-soft: #10281f;
  --warn: #f2b544;
  --warn-soft: #2b2113;
  --bad: #f87171;
  --bad-soft: #2e1817;
  --info: #5eb0ef;
  --info-soft: #12222f;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow: 0 6px 18px rgba(0, 0, 0, .45);
  --shadow-lg: 0 20px 48px rgba(0, 0, 0, .6);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1015;
    --bg-grad: radial-gradient(1200px 600px at 15% -10%, #182033 0%, transparent 60%);
    --surface: #151a21;
    --surface-2: #1b212a;
    --surface-3: #232b36;
    --text: #e9edf2;
    --text-2: #c2cad6;
    --muted: #8b94a3;
    --border: #262e3a;
    --border-strong: #38424f;
    --accent: #7c7cf5;
    --accent-soft: #1e2145;
    --accent-text: #a9a9fb;
    --ok: #3ecf8e;
    --ok-soft: #10281f;
    --warn: #f2b544;
    --warn-soft: #2b2113;
    --bad: #f87171;
    --bad-soft: #2e1817;
    --info: #5eb0ef;
    --info-soft: #12222f;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 6px 18px rgba(0, 0, 0, .45);
    --shadow-lg: 0 20px 48px rgba(0, 0, 0, .6);
  }
}

/* --- Grundlagen ---------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

/* Kein Zoom – weder per Pinch noch per Doppeltipp. Das Viewport-Meta allein
   genügt nicht: iOS ignoriert user-scalable seit iOS 10, dort greifen
   zusätzlich die Gesten-Handler in app.js. */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  touch-action: pan-x pan-y;
  /* Kein Gummiband-Scrollen, kein Pull-to-Refresh, keine Scroll-Ketten. */
  overscroll-behavior: none;
}

/* Waagerechter Überlauf wird abgeschnitten statt die Seite scrollbar zu
   machen. "clip" statt "hidden": hidden erzeugt einen Scroll-Container und
   bricht damit position:sticky bei Topbar und Sidebar. */
html, body {
  overflow-x: hidden; /* Fallback für ältere Browser */
  overflow-x: clip;
  max-width: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 640; letter-spacing: -.012em; line-height: 1.25; }
h1 { font-size: 1.55rem; }
h2 { font-size: 1.12rem; }
h3 { font-size: .98rem; }
p { margin: 0 0 .7em; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1.2rem 0; }

/* Überlauf-Bremsen: nichts darf die Seite breiter machen als den Viewport. */
img, svg, video, canvas, iframe { max-width: 100%; height: auto; }
table { max-width: 100%; }
pre { overflow-x: auto; max-width: 100%; }
code, pre, .mono { overflow-wrap: anywhere; }
/* Lange Wörter (IBANs, Aktenzeichen, Datei- und Mailadressen) umbrechen
   lassen, statt sie aus dem Layout laufen zu lassen. */
h1, h2, h3, h4, p, li, dd, td, th, .lead, .hint, .help { overflow-wrap: anywhere; }

.num, .money, td.num, th.num {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}
.mono { font-family: var(--mono); font-size: .9em; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

::selection { background: var(--accent); color: #fff; }

/* --- Layout -------------------------------------------------------------- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: 1.1rem 1rem .9rem;
  border-bottom: 1px solid var(--border);
}
.brand-mark {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  display: grid; place-items: center;
  color: #fff; font-weight: 800; font-size: .92rem;
  box-shadow: var(--shadow-sm);
  flex: 0 0 auto;
}
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-name { font-weight: 700; font-size: .95rem; letter-spacing: -.01em; }
.brand-sub { font-size: .68rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }

.nav { padding: .7rem .55rem; flex: 1; }
.nav-group + .nav-group { margin-top: 1rem; }
.nav-label {
  font-size: .66rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); padding: .35rem .5rem; font-weight: 600;
}
.nav a {
  display: flex; align-items: center; gap: .55rem;
  padding: .46rem .55rem;
  border-radius: var(--r-sm);
  color: var(--text-2);
  font-weight: 520;
  font-size: .88rem;
  text-decoration: none;
  transition: background .12s, color .12s;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent-text); font-weight: 620; }
.nav a .ico { width: 17px; text-align: center; opacity: .85; flex: 0 0 auto; }
.nav a .count {
  margin-left: auto; font-size: .72rem; padding: 0 .38rem;
  border-radius: 20px; background: var(--surface-3); color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.nav a.active .count { background: var(--accent); color: #fff; }

.sidebar-foot { padding: .7rem; border-top: 1px solid var(--border); font-size: .8rem; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: .8rem;
  padding: .7rem 1.4rem;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 1.12rem; min-width: 0; }
.topbar .spacer { flex: 1; }
.menu-toggle { display: none; }

.content { padding: 1.4rem; max-width: 1500px; width: 100%; }
.content.narrow { max-width: 900px; }

/* --- Buttons ------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .46rem .8rem;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: inherit; font-size: .86rem; font-weight: 560;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s, transform .06s, box-shadow .12s;
  text-decoration: none;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
.btn-danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, var(--border)); }
.btn-danger:hover { background: var(--bad-soft); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: .26rem .55rem; font-size: .78rem; }
.btn-lg { padding: .62rem 1.1rem; font-size: .95rem; }
.btn-block { width: 100%; }

.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* --- Karten -------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.card + .card { margin-top: 1rem; }
.card-head {
  display: flex; align-items: center; gap: .7rem;
  padding: .8rem 1.05rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.card-head h2, .card-head h3 { flex: 1; min-width: 0; }
.card-body { padding: 1.05rem; }
.card-body.tight { padding: .6rem; }
.card-body.flush { padding: 0; }
.card-foot {
  padding: .7rem 1.05rem; border-top: 1px solid var(--border);
  background: var(--surface-2); font-size: .84rem;
}

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); align-items: start; }

/* --- Kennzahlen ---------------------------------------------------------- */
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: .95rem 1.05rem;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}
.stat::after {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--border-strong);
}
.stat.is-receivable::after { background: var(--ok); }
.stat.is-payable::after { background: var(--warn); }
.stat.is-bad::after { background: var(--bad); }
.stat.is-accent::after { background: var(--accent); }

.stat-label {
  font-size: .74rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); font-weight: 620; margin-bottom: .25rem;
}
.stat-value {
  font-size: 1.5rem; font-weight: 680; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}
.stat-value.pos { color: var(--ok); }
.stat-value.neg { color: var(--bad); }
.stat-sub { font-size: .78rem; color: var(--muted); margin-top: .2rem; }

/* --- Badges -------------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: .28rem;
  padding: .1rem .45rem;
  border-radius: 20px;
  font-size: .73rem; font-weight: 620; line-height: 1.5;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-bad { background: var(--bad-soft); color: var(--bad); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-muted { background: var(--surface-3); color: var(--muted); }
.badge-accent { background: var(--accent-soft); color: var(--accent-text); }
.badge-outline { border-color: var(--border-strong); color: var(--text-2); background: transparent; }

.dir-pill {
  display: inline-flex; align-items: center; gap: .3rem;
  font-size: .72rem; font-weight: 700; letter-spacing: .02em;
  padding: .08rem .42rem; border-radius: 5px;
}
.dir-receivable { background: var(--ok-soft); color: var(--ok); }
.dir-payable { background: var(--warn-soft); color: var(--warn); }

/* --- Tabellen ------------------------------------------------------------ */
.table-wrap { overflow-x: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}
table.data th {
  text-align: left;
  font-size: .72rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); font-weight: 640;
  padding: .55rem .7rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  position: sticky; top: 0; z-index: 1;
  white-space: nowrap;
}
table.data th a { color: inherit; }
table.data th.num, table.data td.num { text-align: right; }
table.data td {
  padding: .6rem .7rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data .row-link { color: var(--text); font-weight: 600; }
table.data .sub { font-size: .78rem; color: var(--muted); }
table.data tr.is-overdue td:first-child { box-shadow: inset 3px 0 0 var(--bad); }
table.data tr.is-soon td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
table.data tr.is-done { opacity: .62; }

/* --- Fortschritt --------------------------------------------------------- */
.bar {
  height: 6px; border-radius: 20px; background: var(--surface-3);
  overflow: hidden; min-width: 60px;
}
.bar > span { display: block; height: 100%; border-radius: 20px; background: var(--accent); }
.bar.ok > span { background: var(--ok); }
.bar.warn > span { background: var(--warn); }
.bar.bad > span { background: var(--bad); }
.bar-label { font-size: .72rem; color: var(--muted); margin-top: .2rem; }

.aging-row { display: grid; grid-template-columns: 110px 1fr 110px; gap: .7rem; align-items: center; padding: .3rem 0; }
.aging-row .label { font-size: .82rem; color: var(--text-2); }
.aging-row .value { text-align: right; font-variant-numeric: tabular-nums; font-size: .85rem; font-weight: 600; }
.aging-bar { height: 20px; background: var(--surface-3); border-radius: var(--r-sm); overflow: hidden; }
.aging-bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), #8b5cf6); }

/* --- Formulare ----------------------------------------------------------- */
.form-section {
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  margin-bottom: 1rem;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.form-section > summary, .form-section-head {
  display: flex; align-items: center; gap: .6rem;
  padding: .8rem 1.05rem;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-weight: 640;
  list-style: none;
  user-select: none;
}
.form-section > summary::-webkit-details-marker { display: none; }
.form-section > summary::before {
  content: "▸"; color: var(--muted); font-size: .8rem;
  transition: transform .15s; display: inline-block;
}
.form-section[open] > summary::before { transform: rotate(90deg); }
.form-section > summary .hint { font-weight: 400; color: var(--muted); font-size: .8rem; margin-left: auto; }
.form-section-body { padding: 1.05rem; }

.field { margin-bottom: .9rem; min-width: 0; }
.field:last-child { margin-bottom: 0; }
.field > label, .field-label {
  display: block; font-size: .8rem; font-weight: 600;
  color: var(--text-2); margin-bottom: .28rem;
}
.field .req { color: var(--bad); }
.field .help { font-size: .77rem; color: var(--muted); margin-top: .25rem; line-height: 1.4; }
.field .err { font-size: .78rem; color: var(--bad); margin-top: .25rem; font-weight: 560; }

input[type="text"], input[type="number"], input[type="date"], input[type="email"],
input[type="tel"], input[type="url"], input[type="password"], input[type="search"],
input[type="file"], select, textarea {
  width: 100%;
  padding: .46rem .6rem;
  font: inherit; font-size: .88rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  transition: border-color .12s, box-shadow .12s;
}
input:hover, select:hover, textarea:hover { border-color: var(--muted); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
input.is-error, select.is-error, textarea.is-error {
  border-color: var(--bad);
  background: color-mix(in srgb, var(--bad) 5%, var(--surface));
}
textarea { resize: vertical; min-height: 72px; line-height: 1.5; }
select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
                    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) calc(50% + 1px), calc(100% - 10px) calc(50% + 1px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 1.9rem;
}
input[type="file"] { padding: .35rem; background: var(--surface-2); cursor: pointer; }
input.money { text-align: right; font-variant-numeric: tabular-nums; }

/* iOS zoomt beim Fokus in ein Feld, sobald dessen Schrift kleiner als 16px
   ist – und lässt sich danach nicht mehr herauszoomen, weil user-scalable=no
   greift. Auf Touch-Geräten deshalb mindestens 16px. */
@media (pointer: coarse) {
  input[type="text"], input[type="number"], input[type="date"], input[type="email"],
  input[type="tel"], input[type="url"], input[type="password"], input[type="search"],
  input[type="file"], select, textarea {
    font-size: 16px;
  }
}

.input-group { display: flex; }
.input-group > :first-child { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-group > :last-child { border-top-left-radius: 0; border-bottom-left-radius: 0; margin-left: -1px; }
.input-group .addon {
  display: flex; align-items: center; padding: 0 .6rem;
  background: var(--surface-3); border: 1px solid var(--border-strong);
  color: var(--muted); font-size: .85rem; white-space: nowrap;
}
.input-group select.addon-select { flex: 0 0 auto; width: auto; }

.check {
  display: flex; align-items: flex-start; gap: .55rem;
  padding: .5rem .65rem;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color .12s, background .12s;
}
.check:hover { border-color: var(--border-strong); }
.check input { margin: .18rem 0 0; width: 15px; height: 15px; accent-color: var(--accent); flex: 0 0 auto; cursor: pointer; }
.check:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.check .t { font-size: .85rem; font-weight: 560; }
.check .d { font-size: .77rem; color: var(--muted); line-height: 1.4; }

.row { display: grid; gap: .9rem; }
.row-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.row-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.row-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.form-actions {
  position: sticky; bottom: 0;
  display: flex; gap: .6rem; align-items: center;
  padding: .85rem 1.05rem;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  margin-top: 1rem;
  z-index: 20;
}
.form-actions .spacer { flex: 1; }

/* --- Meldungen ----------------------------------------------------------- */
.alert {
  display: flex; gap: .6rem; align-items: flex-start;
  padding: .7rem .9rem;
  border-radius: var(--r);
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: .87rem;
  margin-bottom: 1rem;
}
.alert-ok { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 28%, transparent); color: var(--ok); }
.alert-warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 28%, transparent); color: var(--warn); }
.alert-error { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 28%, transparent); color: var(--bad); }
.alert-info { background: var(--info-soft); border-color: color-mix(in srgb, var(--info) 28%, transparent); color: var(--info); }
.alert strong { font-weight: 700; }

#flash-host {
  position: fixed; right: 1rem; bottom: 1rem; z-index: 200;
  display: flex; flex-direction: column; gap: .5rem; max-width: min(420px, calc(100vw - 2rem));
}
.toast {
  padding: .7rem .9rem;
  border-radius: var(--r);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg);
  font-size: .87rem;
  animation: toast-in .2s ease-out;
}
.toast.ok { border-left: 3px solid var(--ok); }
.toast.warn { border-left: 3px solid var(--warn); }
.toast.error { border-left: 3px solid var(--bad); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* --- Leerzustand --------------------------------------------------------- */
.empty {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--muted);
}
.empty .icon { font-size: 2.4rem; opacity: .5; margin-bottom: .6rem; }
.empty h3 { color: var(--text); margin-bottom: .35rem; }
.empty p { max-width: 44ch; margin: 0 auto .9rem; }

/* --- Filterleiste -------------------------------------------------------- */
.filters {
  display: flex; gap: .5rem; flex-wrap: wrap; align-items: center;
  padding: .7rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
}
.filters select, .filters input { width: auto; min-width: 130px; font-size: .84rem; padding: .34rem .5rem; }
.filters input[type="search"] { min-width: 220px; flex: 1; }
.filters .spacer { flex: 1; }

.chip {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .2rem .55rem; font-size: .78rem; font-weight: 560;
  border-radius: 20px; border: 1px solid var(--border-strong);
  color: var(--text-2); background: var(--surface);
  cursor: pointer; text-decoration: none;
}
.chip:hover { background: var(--surface-2); text-decoration: none; }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* --- Detailseite --------------------------------------------------------- */
.detail-head {
  display: flex; gap: 1rem; align-items: flex-start; flex-wrap: wrap;
  margin-bottom: 1.1rem;
}
.detail-head .title { flex: 1; min-width: 260px; }
.detail-head h1 { margin-bottom: .3rem; }
.detail-meta { display: flex; gap: .45rem; flex-wrap: wrap; align-items: center; font-size: .82rem; color: var(--muted); }

.kv { display: grid; grid-template-columns: minmax(120px, 34%) 1fr; gap: .1rem .8rem; font-size: .87rem; }
.kv dt { color: var(--muted); padding: .32rem 0; font-size: .82rem; }
.kv dd { margin: 0; padding: .32rem 0; font-weight: 540; min-width: 0; overflow-wrap: anywhere; }
.kv dt, .kv dd { border-bottom: 1px solid var(--border); }
.kv dt:last-of-type, .kv dd:last-of-type { border-bottom: 0; }

.amount-hero {
  display: flex; align-items: baseline; gap: .6rem; flex-wrap: wrap;
  padding: 1rem 1.05rem;
  background: linear-gradient(135deg, var(--surface-2), var(--surface));
  border-bottom: 1px solid var(--border);
}
.amount-hero .big {
  font-size: 2rem; font-weight: 700; letter-spacing: -.025em;
  font-variant-numeric: tabular-nums;
}
.amount-hero .of { color: var(--muted); font-size: .9rem; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  position: relative;
  padding: .55rem 0 .55rem 1.4rem;
  border-bottom: 1px solid var(--border);
  font-size: .86rem;
}
.timeline li:last-child { border-bottom: 0; }
.timeline li::before {
  content: ""; position: absolute; left: 3px; top: .95rem;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--border-strong);
}
.timeline li::after {
  content: ""; position: absolute; left: 6px; top: 1.5rem; bottom: -.55rem;
  width: 1px; background: var(--border);
}
.timeline li:last-child::after { display: none; }
.timeline li.t-ledger::before { background: var(--ok); }
.timeline li.t-dunning::before { background: var(--warn); }
.timeline li.t-status::before { background: var(--accent); }
.timeline li.t-note::before { background: var(--info); }
.timeline .when { color: var(--muted); font-size: .77rem; }

.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(178px, 1fr)); gap: .7rem; }
.doc-card {
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow: hidden;
  background: var(--surface);
  transition: border-color .12s, box-shadow .12s, transform .12s;
  display: flex; flex-direction: column;
}
.doc-card:hover { border-color: var(--accent); box-shadow: var(--shadow); transform: translateY(-1px); }
.doc-thumb {
  height: 108px; display: grid; place-items: center;
  background: var(--surface-3); color: var(--muted);
  font-size: 1.9rem; overflow: hidden; position: relative;
}
.doc-thumb img { width: 100%; height: 100%; object-fit: cover; }
.doc-body { padding: .55rem .65rem; font-size: .8rem; flex: 1; min-width: 0; }
.doc-title { font-weight: 620; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-meta { color: var(--muted); font-size: .74rem; margin-top: .15rem; }
.doc-actions { display: flex; gap: .3rem; padding: .4rem .5rem; border-top: 1px solid var(--border); background: var(--surface-2); }

.dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--r-lg);
  padding: 1.4rem;
  text-align: center;
  color: var(--muted);
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-text); }
.dropzone .big { font-size: 1.6rem; display: block; margin-bottom: .3rem; }
.dropzone .files { margin-top: .6rem; font-size: .82rem; color: var(--text-2); text-align: left; }

/* --- Login --------------------------------------------------------------- */
.auth-wrap {
  min-height: 100vh;
  display: grid; place-items: center;
  padding: 1.5rem;
}
.auth-card {
  width: min(430px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  padding: 2rem 1.8rem;
  text-align: center;
}
.auth-card .brand-mark { width: 46px; height: 46px; font-size: 1.25rem; margin: 0 auto .9rem; border-radius: 12px; }
.auth-card h1 { font-size: 1.35rem; margin-bottom: .3rem; }
.auth-card .lead { color: var(--muted); font-size: .9rem; margin-bottom: 1.4rem; }
.auth-card .field { text-align: left; }
.auth-note { font-size: .8rem; color: var(--muted); margin-top: 1.2rem; line-height: 1.5; }

/* --- Sonstiges ----------------------------------------------------------- */
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.tiny { font-size: .75rem; }
.strong { font-weight: 650; }
.pos { color: var(--ok); }
.neg { color: var(--bad); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: .5rem; } .mb-2 { margin-bottom: 1rem; }
.flex { display: flex; gap: .5rem; align-items: center; }
.flex-wrap { flex-wrap: wrap; }
.gap-sm { gap: .35rem; }
.hidden { display: none !important; }

.inline-form { display: inline; }

.tabs { display: flex; gap: .2rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; overflow-x: auto; }
.tabs a {
  padding: .5rem .8rem; font-size: .87rem; font-weight: 580;
  color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--accent-text); border-bottom-color: var(--accent); }

.pagination { display: flex; gap: .3rem; justify-content: center; margin-top: 1.2rem; flex-wrap: wrap; }

.seg-total {
  font-variant-numeric: tabular-nums;
  font-size: .82rem;
}
table.mini { width: 100%; border-collapse: collapse; font-size: .8rem; }
table.mini td, table.mini th { padding: .3rem .45rem; border-bottom: 1px solid var(--border); text-align: left; }
table.mini th { color: var(--muted); font-weight: 600; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; }
table.mini td.num, table.mini th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* --- Responsive ---------------------------------------------------------- */
@media (max-width: 1100px) {
  .grid-main { grid-template-columns: minmax(0, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar {
    position: static; width: 100%; height: auto; flex: none;
    border-right: 0; border-bottom: 1px solid var(--border);
  }
  .sidebar.collapsed .nav, .sidebar.collapsed .sidebar-foot { display: none; }
  .menu-toggle { display: inline-flex; }
  .content { padding: 1rem .8rem; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
  .row-2, .row-3, .row-4 { grid-template-columns: minmax(0, 1fr); }
  .kv { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .kv dt { border-bottom: 0; padding-bottom: 0; }
  .form-actions { position: sticky; bottom: .5rem; }
  .topbar { padding: .6rem .8rem; }
  .aging-row { grid-template-columns: 90px 1fr 90px; gap: .4rem; }
}

@media print {
  .sidebar, .topbar, .form-actions, .btn, .filters, #flash-host { display: none !important; }
  body { background: #fff; }
  .card { break-inside: avoid; box-shadow: none; }
}
