:root {
    --canvas: #eceef1;
    --surface: #ffffff;
    --ink: #1c2530;
    --muted: #5b6776;
    --line: #e2e6ea;
    --primary: #0f5b66;
    --primary-hover: #0c4a53;
    --primary-soft: #e4eef0;
    --danger: #b23b3b;
    --danger-soft: #f7e4e4;
    --radius: 10px;
    --shadow: 0 8px 24px rgba(28, 37, 48, 0.08);
    --topbar-h: 60px;
    --menu-w: 260px;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
}

body {
    font-family: var(--font);
    color: var(--ink);
    background: var(--canvas);
}

/* ---------- Marke ---------- */
.brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}
.brand-mark {
    width: 22px;
    height: 22px;
    border-radius: 6px;
    background: var(--primary);
    box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.35);
}
.brand-name {
    font-weight: 650;
    letter-spacing: 0.01em;
}

/* ---------- Buttons ---------- */
.btn {
    font: inherit;
    font-weight: 600;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 0.55rem 1.1rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}
.btn-primary {
    background: var(--primary);
    color: #fff;
    width: 100%;
    padding: 0.7rem 1.1rem;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost {
    background: transparent;
    color: var(--muted);
    border-color: var(--line);
}
.btn-ghost:hover { color: var(--ink); border-color: var(--muted); }

:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* =========================================================
   LOGIN
   ========================================================= */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}
.login-card {
    background: var(--surface);
    width: 100%;
    max-width: 380px;
    padding: 2.25rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.login-card .brand { margin-bottom: 1.75rem; }
.login-card h1 {
    margin: 0 0 1.25rem;
    font-size: 1.4rem;
}
.form { display: flex; flex-direction: column; gap: 1rem; }
.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field span { font-size: 0.85rem; color: var(--muted); }
.field input {
    font: inherit;
    padding: 0.6rem 0.7rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcfd;
}
.field input:focus {
    border-color: var(--primary);
    outline: none;
    background: #fff;
}

.alert {
    margin: 0 0 1rem;
    padding: 0.6rem 0.8rem;
    border-radius: 8px;
    font-size: 0.88rem;
}
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-info  { background: var(--primary-soft); color: var(--primary-hover); }

/* =========================================================
   APP-LAYOUT
   ========================================================= */
.layout {
    height: 100dvh;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: var(--topbar-h);
    flex: 0 0 auto;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.25rem;
}
.topbar-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}
.user { font-size: 0.88rem; color: var(--muted); }
.logout-form { margin: 0; }

.menu-toggle {
    width: 40px;
    height: 40px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.menu-toggle:hover { border-color: var(--muted); }
.menu-toggle-bars,
.menu-toggle-bars::before,
.menu-toggle-bars::after {
    content: "";
    display: block;
    width: 18px;
    height: 2px;
    background: var(--ink);
    position: relative;
}
.menu-toggle-bars::before { position: absolute; top: -6px; }
.menu-toggle-bars::after  { position: absolute; top: 6px; }

.workspace {
    flex: 1 1 auto;
    display: flex;
    align-items: stretch;
    min-height: 0;
}

/* LINKS: Content */
.content {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    padding: 1.1rem 1.5rem 1.25rem;
    overflow: hidden;
}
.content h1 { margin: 0 0 0.75rem; font-size: 1.3rem; }

/* RECHTS: aufklappbares Menü */
.sidemenu {
    flex: 0 0 var(--menu-w);
    width: var(--menu-w);
    background: var(--surface);
    border-right: 1px solid var(--line);
    overflow: hidden;
    transition: flex-basis 0.22s ease, width 0.22s ease;
}
.sidemenu nav {
    width: var(--menu-w);   /* feste Breite -> kein Stauchen beim Zuklappen */
    padding: 1.25rem 1rem;
}
.menu-titel {
    margin: 0 0 0.75rem;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
}
.sidemenu ul { list-style: none; margin: 0; padding: 0; }
.sidemenu li { margin-bottom: 0.15rem; }
.sidemenu a {
    display: block;
    padding: 0.55rem 0.7rem;
    border-radius: 8px;
    text-decoration: none;
    color: var(--ink);
    border-left: 3px solid transparent;
}
.sidemenu a:hover { background: var(--canvas); }
.sidemenu a.active {
    background: var(--primary-soft);
    border-left-color: var(--primary);
    color: var(--primary-hover);
    font-weight: 600;
}

/* Zustand: Menü eingeklappt */
.layout.menu-collapsed .sidemenu {
    flex-basis: 0;
    width: 0;
    border-right-color: transparent;
}

/* ---------- Mobil ---------- */
@media (max-width: 820px) {
    .user { display: none; }
    .workspace { flex-direction: column; }
    .sidemenu {
        flex-basis: auto;
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--line);
        transition: none;
    }
    .sidemenu nav { width: 100%; }
    .layout.menu-collapsed .sidemenu { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; }
}

/* =========================================================
   ÜBERSICHT: Filter + Ergebnis
   ========================================================= */
.filter-card,
.results-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

/* Filter: kompakt, max. 1/4 der Hoehe */
.filter-card {
    flex: 0 0 auto;
    max-height: 25vh;
    overflow-y: auto;
    padding: 0.8rem 1rem;
    margin-bottom: 0.85rem;
}
.filter-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.7rem;
}

.card-titel {
    margin: 0;
    font-size: 0.9rem;
    font-weight: 650;
}

/* Filter: 2 Spalten, Beschriftung vor dem Feld */
.filter-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.45rem 1.5rem;
}
.filter-grid .field {
    display: grid;
    grid-template-columns: 130px 1fr;
    align-items: center;
    gap: 0.6rem;
}
.filter-grid .field span { font-size: 0.82rem; color: var(--muted); }
.filter-grid .field input,
.filter-grid .field select {
    font: inherit;
    font-size: 0.88rem;
    width: 100%;
    padding: 0.32rem 0.5rem;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fbfcfd;
}
.filter-grid .field input:focus,
.filter-grid .field select:focus {
    border-color: var(--primary);
    outline: none;
    background: #fff;
}

.filter-actions {
    display: flex;
    gap: 0.5rem;
}
.filter-actions .btn { width: auto; }
.btn-sm { padding: 0.35rem 0.85rem; font-size: 0.85rem; }

/* Ergebnis: fuellt den Rest, scrollt intern */
.results-card {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 0.8rem 1rem 0.5rem;
}
.results-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.5rem;
}
.results-info { color: var(--muted); font-size: 0.82rem; margin: 0; }

.results-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
}
table.results { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
table.results th,
table.results td {
    text-align: left;
    padding: 0.45rem 0.7rem;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}
table.results thead th {
    position: sticky;
    top: 0;
    background: var(--surface);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    font-weight: 600;
    z-index: 1;
}
table.results tbody tr:hover { background: var(--canvas); }

/* Status-Badges */
.badge {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    background: #eef2f7;
    color: #475569;
}
.badge-offen         { background: #eef2f7; color: #475569; }
.badge-bearbeitung   { background: var(--primary-soft); color: var(--primary-hover); }
.badge-abgeschlossen { background: #e6f4ea; color: #2f7d4f; }
.badge-storniert     { background: var(--danger-soft); color: var(--danger); }

@media (max-width: 820px) {
    .filter-card { max-height: none; }
    .filter-grid { grid-template-columns: 1fr; }
    .filter-grid .field { grid-template-columns: 110px 1fr; }
}

.results-empty {
    text-align: center;
    color: var(--muted);
    padding: 1.5rem;
}

/* =========================================================
   Ergebnis: anklickbare Zeilen + Verlinkung
   ========================================================= */
table.results tbody tr[data-href] { cursor: pointer; }
table.results a { color: var(--primary); text-decoration: none; font-weight: 600; }
table.results a:hover { text-decoration: underline; }

/* =========================================================
   VORGANG: Detailansicht mit Tabs
   ========================================================= */
.detail-head {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.85rem;
}
.detail-head h1 { margin: 0; font-size: 1.3rem; }

.hinweis {
    flex: 0 0 auto;
    margin: 0 0 0.85rem;
    padding: 0.6rem 0.8rem;
    border-radius: 8px;
    background: var(--primary-soft);
    color: var(--primary-hover);
    font-size: 0.88rem;
}

/* Tab-Leiste */
.tablist {
    flex: 0 0 auto;
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    border-bottom: 1px solid var(--line);
}
.tab {
    font: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--muted);
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 0.6rem 0.9rem;
    margin-bottom: -1px;
    cursor: pointer;
}
.tab:hover { color: var(--ink); }
.tab.is-active {
    color: var(--primary-hover);
    border-bottom-color: var(--primary);
}

/* Tab-Inhalte: fuellen den Rest und scrollen intern */
.tabpanels {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    padding-top: 1.1rem;
}

.panel-titel {
    margin: 0 0 0.75rem;
    font-size: 0.95rem;
    font-weight: 650;
}
.tabpanel .panel-titel:not(:first-child) { margin-top: 1.5rem; }

.platzhalter-note { color: var(--muted); font-size: 0.86rem; margin: 1rem 0 0; }

/* Formularraster der Detailansicht (Beschriftung ueber dem Feld) */
.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.85rem 1.5rem;
    max-width: 900px;
}
.detail-grid .field { display: flex; flex-direction: column; gap: 0.3rem; }
.detail-grid .field span { font-size: 0.8rem; color: var(--muted); }
.detail-grid .field input,
.detail-grid .field select {
    font: inherit;
    font-size: 0.9rem;
    width: 100%;
    padding: 0.45rem 0.6rem;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fbfcfd;
}
.detail-grid .field input:focus,
.detail-grid .field select:focus {
    border-color: var(--primary);
    outline: none;
    background: #fff;
}
.detail-grid .field input[readonly],
.detail-grid .field input:disabled {
    background: #f1f3f5;
    color: var(--muted);
}

.detail-actions { margin-top: 1.25rem; }

@media (max-width: 820px) {
    .detail-grid { grid-template-columns: 1fr; }
}

/* =========================================================
   VORGANGSDATEN (Tab 1): Boxen im Zwei-Spalten-Layout
   ========================================================= */
.detail-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
    align-items: start;
}
.detail-col {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.box {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    padding: 0.6rem 1.1rem 1rem;
    margin: 0;
}
.box legend {
    font-weight: 650;
    font-size: 0.9rem;
    padding: 0 0.4rem;
    color: var(--ink);
}

.box-grid {
    display: grid;
    grid-template-columns: minmax(140px, max-content) 1fr;
    gap: 0.4rem 1rem;
    align-items: center;
}
.box-grid .label { color: var(--muted); font-size: 0.85rem; }
.box-grid .wert  { font-size: 0.9rem; }
.box-grid input[type="text"],
.box-grid input[type="date"],
.box-grid input[type="datetime-local"],
.box-grid select {
    font: inherit;
    font-size: 0.88rem;
    width: 100%;
    padding: 0.32rem 0.5rem;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fbfcfd;
}
.box-grid input:focus,
.box-grid select:focus { border-color: var(--primary); outline: none; background: #fff; }
.box-grid input:disabled,
.box-grid select:disabled { background: #f1f3f5; color: var(--muted); }
.box-grid input[type="checkbox"] { width: 16px; height: 16px; justify-self: start; }

/* Unterüberschrift innerhalb einer Box (z. B. "Daten") */
.box-grid .subhead {
    grid-column: 1 / -1;
    font-weight: 600;
    font-size: 0.82rem;
    color: var(--ink);
    border-bottom: 1px solid var(--line);
    padding-bottom: 0.2rem;
    margin-top: 0.4rem;
    min-height: 0.6rem;
}

.box-actions { display: flex; gap: 0.4rem; margin-top: 0.9rem; }
.box-actions .btn { width: auto; }
.btn:disabled { opacity: 0.5; cursor: default; }

@media (max-width: 980px) {
    .detail-columns { grid-template-columns: 1fr; }
}

/* ---- Tab 2: Personendaten ------------------------------------------------ */
.person-actions { display: flex; gap: 0.4rem; margin-bottom: 1rem; }
.person-actions .btn { width: auto; }

.person-columns {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.25rem;
    align-items: start;
}

/* Kommunikationszeilen (Telefon/Handy/E-Mail) mit mehreren Teilfeldern */
.komm-zeile {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 0.6rem;
}
.komm-zeile .label { flex: 0 0 70px; color: var(--muted); font-size: 0.85rem; }
.komm-zeile input[type="text"] {
    font: inherit;
    font-size: 0.88rem;
    padding: 0.32rem 0.5rem;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fbfcfd;
}
.komm-zeile input:focus { border-color: var(--primary); outline: none; background: #fff; }
.komm-zeile input:disabled { background: #f1f3f5; color: var(--muted); }
.komm-klein  { width: 80px; }
.komm-nummer { flex: 1 1 120px; min-width: 100px; }
.komm-check {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.8rem;
    color: var(--muted);
    white-space: nowrap;
}
.komm-check input[type="checkbox"] { width: 16px; height: 16px; }

@media (max-width: 1100px) {
    .person-columns { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 820px) {
    .person-columns { grid-template-columns: 1fr; }
}

/* Blätterleiste der Trefferliste */
.pagination {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    justify-content: center;
    align-items: center;
    padding: 0.75rem 0 0.35rem;
    flex: 0 0 auto;
}
.pagination .btn { width: auto; }
.pagination .seiten-nr { min-width: 2.4rem; }

/* ---- Tab 3: Kundenkommunikation (E-Mail) --------------------------------- */
.mail-form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-width: 0;
}
.mail-row {
    display: grid;
    grid-template-columns: 110px 1fr;
    align-items: center;
    gap: 0.75rem;
}
.mail-row-text {
    align-items: start;
}
.mail-label {
    color: var(--muted);
    font-size: 0.9rem;
    text-align: right;
}
.mail-input {
    font: inherit;
    font-size: 0.92rem;
    padding: 0.45rem 0.6rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcfd;
    width: 100%;
}
.mail-input:focus {
    border-color: var(--primary);
    outline: none;
    background: #fff;
}
.mail-text {
    resize: vertical;
    line-height: 1.5;
    min-height: 220px;
}
.mail-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    padding-top: 0.25rem;
}
.mail-actions .btn { width: auto; }

/* Fehlermeldung (Flash) */
.fehler {
    margin: 0.4rem 0 0;
    padding: 0.6rem 0.85rem;
    border-radius: 8px;
    background: #fdecec;
    border: 1px solid #f5c2c2;
    color: #9b1c1c;
    font-size: 0.92rem;
}

@media (max-width: 640px) {
    .mail-row { grid-template-columns: 1fr; }
    .mail-label { text-align: left; }
}

/* Tab 3: Formular + Inline-Vorschau nebeneinander */
.mail-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 1.5rem;
    align-items: start;
}
.mail-vorschau {
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.mail-vorschau-titel {
    color: var(--muted);
    font-size: 0.9rem;
    margin-bottom: 0.4rem;
}
.mail-vorschau-frame {
    width: 100%;
    min-height: 520px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

@media (max-width: 900px) {
    .mail-layout { grid-template-columns: 1fr; }
    .mail-vorschau-frame { min-height: 360px; }
}

/* ---- Tab 4: Journal ------------------------------------------------------ */
.journal-wrap {
    overflow-x: auto;
}
.journal-tabelle {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}
.journal-tabelle thead th {
    text-align: left;
    color: var(--muted);
    font-weight: 600;
    font-size: 0.8rem;
    padding: 0.4rem 0.6rem;
    border-bottom: 1px solid var(--line);
}
.journal-zeile > td {
    padding: 0.45rem 0.6rem;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
}
.journal-zeile.hat-inhalt {
    cursor: pointer;
}
.journal-zeile.hat-inhalt:hover {
    background: #f6f8fa;
}
.j-toggle {
    width: 26px;
    text-align: center;
    color: var(--muted);
}
.j-chevron {
    display: inline-block;
    font-size: 0.7rem;
    transition: transform 0.15s ease;
}
.journal-zeile.offen .j-chevron {
    transform: rotate(90deg);
}
.j-datum { white-space: nowrap; }
.j-art, .j-kontakt, .j-benutzer { white-space: nowrap; }
.j-text { width: 100%; }

.journal-detail > td {
    padding: 0;
    border-bottom: 1px solid var(--line);
    background: #fbfcfd;
}
.journal-inhalt {
    white-space: pre-wrap;
    line-height: 1.5;
    font-size: 0.88rem;
    color: #333;
    padding: 0.7rem 0.9rem;
}

/* ---- Tab 5: Rechnungen --------------------------------------------------- */
.rg-saldo {
    font-size: 1rem;
    margin: 0 0 1rem;
}
.rg-titel {
    font-size: 0.95rem;
    margin: 1.2rem 0 0.5rem;
    color: var(--ink);
}
.rg-wrap {
    overflow-x: auto;
}
.rg-tabelle {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}
.rg-tabelle thead th {
    text-align: left;
    color: var(--muted);
    font-weight: 600;
    font-size: 0.78rem;
    padding: 0.4rem 0.6rem;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}
.rg-tabelle tbody td {
    padding: 0.4rem 0.6rem;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}
.rg-num {
    text-align: right;
}
.rg-check {
    text-align: center;
}

/* Tab 5: editierbare Blöcke */
.rg-block-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin: 1.2rem 0 0.5rem;
}
.rg-actions {
    display: flex;
    gap: 0.4rem;
}
.rg-actions .btn { width: auto; }
.rg-tabelle td { vertical-align: middle; }
.rg-tabelle input,
.rg-tabelle select {
    font: inherit;
    font-size: 0.85rem;
    padding: 0.28rem 0.4rem;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    width: 100%;
    box-sizing: border-box;
}
.rg-tabelle input:focus,
.rg-tabelle select:focus {
    border-color: var(--primary);
    outline: none;
}
.rg-tabelle input:disabled,
.rg-tabelle select:disabled {
    background: #f1f3f5;
    color: #333;
    border-color: transparent;
}
.rg-betrag { text-align: right; }
.rg-tabelle .rg-check input { width: auto; }

/* Tab 5: leeres Datumsfeld ohne "TT.MM.JJJJ" anzeigen */
/* Leeres Datums-/Zeitfeld ohne "TT.MM.JJJJ --:--" anzeigen (global) */
input[type="date"].leer:not(:focus),
input[type="datetime-local"].leer:not(:focus),
input[type="time"].leer:not(:focus) {
    color: transparent;
}
/* Löschen-Button je Forderung */
.rg-del-col {
    width: 28px;
    text-align: center;
}
.rg-del {
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    padding: 0.15rem 0.35rem;
    border-radius: 6px;
}
.rg-del:hover {
    color: #9b1c1c;
    background: #fdecec;
}

/* ---- Tab 6: Dokumente ---------------------------------------------------- */
.dok-upload {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1.2rem;
}
.dok-upload .dok-art {
    font: inherit;
    font-size: 0.88rem;
    padding: 0.35rem 0.5rem;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fbfcfd;
}
.dok-upload .btn { width: auto; }
.dok-wrap { overflow-x: auto; }
.dok-tabelle {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}
.dok-tabelle thead th {
    text-align: left;
    color: var(--muted);
    font-weight: 600;
    font-size: 0.8rem;
    padding: 0.4rem 0.6rem;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}
.dok-tabelle tbody td {
    padding: 0.45rem 0.6rem;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}
.dok-tabelle a { color: var(--primary); text-decoration: none; }
.dok-tabelle a:hover { text-decoration: underline; }

/* Aktionsspalte der Zahlungen (PDF + Löschen) */
.rg-aktionen {
    white-space: nowrap;
    text-align: right;
}
.rg-aktionen .btn { width: auto; }
.rg-pdf { margin-right: 0.3rem; }

/* ---- Ratenzahlung / Zahlungsaufschub ------------------------------------- */
.rate-form {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.6rem 1rem;
    margin-bottom: 0.6rem;
}
.rate-feld {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}
.rate-feld label {
    font-size: 0.78rem;
    color: var(--muted);
}
.rate-feld input,
.rate-feld select {
    font: inherit;
    font-size: 0.88rem;
    padding: 0.32rem 0.5rem;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fbfcfd;
}
.rate-feld input:focus,
.rate-feld select:focus { border-color: var(--primary); outline: none; background: #fff; }
.rate-submit .btn { width: auto; }

/* Frühere Anschriften (Voranschriften) */
.voranschrift-liste {
    list-style: none;
    margin: 0;
    padding: 0;
    font-size: 0.88rem;
}
.voranschrift-liste li {
    padding: 0.4rem 0;
    border-bottom: 1px solid var(--line);
    color: var(--muted);
}
.voranschrift-liste li:last-child { border-bottom: none; }

/* Neutrale Badges in der Kopfzeile (Kundennummer, Vorgangsnummer) */
.detail-head .badge-neutral {
    background: #eef1f4;
    color: var(--muted);
    border: 1px solid var(--line);
    font-weight: 500;
}

/* ---- Menü: Untermenü (Systemfunktionen) ---------------------------------- */
.menu-gruppe-titel {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.5rem 0.75rem;
    font: inherit;
    font-size: 0.92rem;
    color: inherit;
    background: none;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    text-align: left;
}
.menu-gruppe-titel:hover { background: rgba(255, 255, 255, 0.08); }
.menu-chevron { font-size: 0.75rem; opacity: 0.7; }
.menu-unter { list-style: none; margin: 0.1rem 0 0.2rem 0; padding: 0 0 0 0.75rem; }
.menu-unter a { font-size: 0.88rem; }

/* ---- Dateiupload --------------------------------------------------------- */
.upload-form {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.6rem 1.2rem;
    padding: 1rem;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 12px;
    margin-bottom: 1rem;
}
.upload-feld { display: flex; flex-direction: column; gap: 0.25rem; }
.upload-feld label { font-size: 0.78rem; color: var(--muted); }
.upload-feld select,
.upload-feld input[type="file"] {
    font: inherit;
    font-size: 0.9rem;
    padding: 0.35rem 0.5rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcfd;
}
.upload-feld select:focus,
.upload-feld input[type="file"]:focus { border-color: var(--primary); outline: none; background: #fff; }

/* ---- Report -------------------------------------------------------------- */
.report {
    padding: 1rem;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 12px;
}
.report-head { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.75rem; }
.report-head h2 { margin: 0; font-size: 1rem; }
.badge-ok { background: #e7f6ec; color: #1c7c3c; border: 1px solid #bfe3cb; }
.badge-fehler { background: #fdecec; color: #b42318; border: 1px solid #f3c2be; }
.report-meta {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.25rem 1rem;
    margin: 0 0 0.75rem 0;
    font-size: 0.9rem;
}
.report-meta dt { color: var(--muted); }
.report-meta dd { margin: 0; }
.report-log {
    margin: 0;
    padding: 0.75rem;
    background: #f7f8fa;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 0.85rem;
    white-space: pre-wrap;
    max-height: 420px;
    overflow: auto;
}

/* ---- Forderungen & Zahlungen: zweispaltiges Ergebnis --------------------- */
/* Der Split ersetzt die results-card als direktes Flex-Kind von .content und
   muss deren Rolle uebernehmen: den Rest der Hoehe fuellen und schrumpfen
   duerfen (min-height:0), damit die Karten darin intern scrollen koennen. */
.split-2 {
    flex: 1 1 auto;
    min-height: 0;
    display: grid;
    /* Die Diagrammspalte braucht Platz fuer Beschriftung und Betraege in der
       Legende; die Liste bekommt den Rest. */
    grid-template-columns: minmax(0, 1fr) 420px;
    gap: 1rem;
    align-items: stretch;
}
/* Beide Karten fuellen ihre Spalte und scrollen intern. */
.split-2 > .results-card {
    min-height: 0;
    overflow: hidden;
}
/* Rechte Spalte: die Diagramme scrollen. */
.split-2 .diagramme {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
}

@media (max-width: 1100px) {
    /* Untereinander: dann scrollt der gesamte Bereich statt jeder Karte. */
    .split-2 {
        grid-template-columns: minmax(0, 1fr);
        overflow-y: auto;
    }
    .split-2 > .results-card { overflow: visible; }
    .split-2 .diagramme { overflow: visible; }
}

/* Checkbox-Feld im Filter (Label über der Box wie bei den anderen Feldern) */
.field-check input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin-top: 0.35rem;
    accent-color: var(--primary);
}

/* Betragsspalte rechtsbündig */
.results td.rechts, .results th.rechts { text-align: right; white-space: nowrap; }

/* Namensspalte: schmal halten, zu lange Namen mit „…" kuerzen.
   Die Kuerzung greift am inneren span, da td-Breiten in Tabellen
   nicht zuverlaessig begrenzt werden koennen. Der volle Name steht im title. */
.results td.spalte-name, .results th.spalte-name {
    width: 1%;              /* so schmal wie moeglich */
    max-width: 180px;
}
.results td.spalte-name span {
    display: block;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---- Diagramme ----------------------------------------------------------- */
.diagramme {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 0.25rem;
}
.diagramm {
    margin: 0;
    padding: 0.75rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fbfcfd;
}
.diagramm figcaption {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    font-size: 0.88rem;
    font-weight: 600;
}
.diagramm-gesamt { color: var(--muted); font-weight: 400; }

/* Torte links, Legende rechts daneben – nutzt die schmale Spalte besser. */
.diagramm-body {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.torte { flex: 0 0 auto; }
.torte svg { width: 120px; height: 120px; }

.legende { list-style: none; margin: 0; padding: 0; font-size: 0.78rem; flex: 1 1 auto; min-width: 0; }
.legende li {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.1rem 0;
}
.legende-farbe {
    width: 10px; height: 10px;
    border-radius: 2px;
    flex: 0 0 auto;
}
.legende-text {
    flex: 1 1 auto;
    min-width: 0;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
/* Betraege koennen breit werden – nicht umbrechen und nicht schrumpfen. */
.legende-wert {
    flex: 0 0 auto;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* ---- Benutzerverwaltung: einmalige Passwortanzeige ----------------------- */
.passwort-box {
    padding: 0.9rem 1rem;
    margin-bottom: 1rem;
    background: #fff8e6;
    border: 1px solid #e6d3a3;
    border-radius: var(--radius);
}
.passwort-box p { margin: 0 0 0.5rem 0; font-size: 0.9rem; }
.passwort-wert {
    font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
    font-size: 1.35rem !important;
    letter-spacing: 0.06em;
    user-select: all;              /* ein Klick markiert alles */
    padding: 0.4rem 0.6rem;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    display: inline-block;
    margin: 0 !important;
}

/* Hinweis-/Fehlermeldungen auf den Systemseiten */
.hinweis, .fehler {
    padding: 0.6rem 0.9rem;
    margin-bottom: 1rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
}
.hinweis { background: #e7f6ec; border: 1px solid #bfe3cb; color: #1c7c3c; }
.fehler  { background: var(--danger-soft); border: 1px solid #f3c2be; color: var(--danger); }
.hinweis-klein { font-size: 0.82rem; color: var(--muted); }