/* Rechnungsverwaltung – zentrale Styles */

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: #f3f4f6;
    color: #111827;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Loading-Overlay für Formular-Absendungen (E-Mail senden, Speichern, etc.) */
.page-loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(15, 23, 42, 0.5);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}
.page-loading-overlay.is-visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}
.page-loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: page-loading-spin 0.8s linear infinite;
}
.page-loading-text {
    margin: 1rem 0 0 0;
    color: #fff;
    font-size: 1rem;
    font-weight: 500;
}
@keyframes page-loading-spin {
    to { transform: rotate(360deg); }
}

/* Header & Navigation */
header {
    background: #ffffff;
    padding: 1.2rem 1.8rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.1);
    position: sticky;
    top: 0;
    z-index: 10;
    overflow: visible;
}

.header-inner {
    display: flex;
    align-items: center;
    gap: 1.2rem;
}

header h1 {
    margin: 0;
    font-size: 1.3rem;
    letter-spacing: 0.02em;
    color: #111827;
}

header nav {
    display: flex;
    gap: 0.5rem;
    font-size: 0.9rem;
}

header nav a {
    text-decoration: none;
    color: #4b5563;
}

header nav a:hover {
    color: #111827;
}

header nav a.highlight {
    color: #2563eb;
    font-weight: 500;
}

header > span {
    opacity: 0.7;
    font-size: 0.9rem;
    color: #6b7280;
}

.header-logo {
    height: 4rem;
    width: auto;
    max-height: 80px;
    display: block;
    object-fit: contain;
    position: relative;
    z-index: 1;
}

/* Burger-Button: nur auf Mobile sichtbar */
.header-burger {
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 0.5rem;
    touch-action: manipulation;
    transition: background 0.2s;
}
.header-burger:hover {
    background: #f3f4f6;
}
.header-burger-bar {
    display: block;
    width: 22px;
    height: 2px;
    background: #4b5563;
    border-radius: 1px;
    transition: transform 0.25s, opacity 0.25s;
}

/* Main & Card */
main {
    flex: 1;
    max-width: 1500px;
    width: 100%;
    margin: 2rem auto;
    padding: 0 1.5rem 2rem;
}

.card {
    background: #ffffff;
    border-radius: 1.2rem;
    padding: 1.5rem 1.7rem;
    box-shadow: 0 18px 45px rgba(15, 23, 42, 0.08), 0 0 0 1px rgba(209, 213, 219, 0.7);
}

/* Rechnungsformular: Speichern-Button fixiert am unteren Bildschirmrand beim Scrollen */
.invoice-form {
    padding-bottom: 5rem;
}
.invoice-form-submit-bar {
    position: sticky;
    bottom: 0;
    left: 0;
    right: 0;
    margin: 1.5rem -1.7rem -1.5rem -1.7rem;
    padding: 1rem 1.7rem;
    background: #ffffff;
    border-top: 1px solid #e5e7eb;
    box-shadow: 0 -4px 12px rgba(15, 23, 42, 0.06);
    z-index: 5;
}

/* Listen-Seiten: Floating-Button unten (wie Speichern-Leiste) */
.list-page-float-bar {
    position: sticky;
    bottom: 0;
    left: 0;
    right: 0;
    margin: 1.5rem -1.7rem -1.5rem -1.7rem;
    padding: 1rem 1.7rem;
    background: #ffffff;
    border-top: 1px solid #e5e7eb;
    box-shadow: 0 -4px 12px rgba(15, 23, 42, 0.06);
    z-index: 5;
    border-radius: 0 0 1.2rem 1.2rem;
}

/* Listen-Seiten: Kopf (Titel + Suche) beim Scrollen oben fix */
.list-page-sticky-top {
    position: sticky;
    top: 0;
    z-index: 4;
    background: #ffffff;
    margin: -1.5rem -1.7rem 0 -1.7rem;
    padding: 1.5rem 1.7rem 1rem;
    border-bottom: 1px solid #e5e7eb;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
    border-radius: 1.2rem 1.2rem 0 0;
}

/* Listen-Seiten: Scroll-Container für Tabelle, damit Tabellenkopf sticky funktioniert */
.list-table-scroll-wrap {
    margin-top: 1rem;
    overflow: auto;
    max-height: min(60vh, 600px);
    border-radius: 0.9rem;
    border: 1px solid #e5e7eb;
}

.list-table-scroll-wrap .invoice-list-table {
    margin-top: 0;
    border-radius: 0;
    overflow: visible;
    table-layout: fixed;
    min-width: 63em; /* Summe der Spalten */
}

.list-table-scroll-wrap .invoice-list-table .col-nr       { width: 5em; }
.list-table-scroll-wrap .invoice-list-table .col-kunde   { width: 10em; }
.list-table-scroll-wrap .invoice-list-table .col-betreff { width: 10em; }
.list-table-scroll-wrap .invoice-list-table .col-bauvorhaben { width: 9em; }
.list-table-scroll-wrap .invoice-list-table .col-datum   { width: 5em; }
.list-table-scroll-wrap .invoice-list-table .col-status  { width: 6.5em; }
.list-table-scroll-wrap .invoice-list-table .col-pdf-email { width: 9em; }
.list-table-scroll-wrap .invoice-list-table .col-aktion  { width: 9em; }

.list-table-scroll-wrap .invoice-list-table td.col-nr,
.list-table-scroll-wrap .invoice-list-table td.col-datum,
.list-table-scroll-wrap .invoice-list-table td.col-status,
.list-table-scroll-wrap .invoice-list-table td.col-aktion {
    white-space: nowrap;
}

.list-table-scroll-wrap .invoice-list-table td.col-kunde,
.list-table-scroll-wrap .invoice-list-table td.col-betreff,
.list-table-scroll-wrap .invoice-list-table td.col-pdf-email {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 0;
}

.list-table-scroll-wrap table {
    margin-top: 0;
    border-radius: 0;
    overflow: visible;
}

.list-table-scroll-wrap thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #eff6ff;
    border-bottom: 1px solid #d1d5db;
    box-shadow: 0 1px 0 0 #d1d5db;
}

.list-table-scroll-wrap .col-bauvorhaben {
    max-width: 10em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.list-table-scroll-wrap .customer-list-table {
    table-layout: fixed;
    width: 100%;
}
.list-table-scroll-wrap .customer-list-table .col-name { width: 18%; }
.list-table-scroll-wrap .customer-list-table .col-email { width: 18%; }
.list-table-scroll-wrap .customer-list-table .col-address { width: 28%; }
.list-table-scroll-wrap .customer-list-table .col-status { width: 8%; }
.list-table-scroll-wrap .customer-list-table .col-aktion { width: 28%; }

.list-table-scroll-wrap .user-list-table {
    table-layout: fixed;
    width: 100%;
}
.list-table-scroll-wrap .user-list-table .col-name { width: 18%; }
.list-table-scroll-wrap .user-list-table .col-email { width: 22%; }
.list-table-scroll-wrap .user-list-table .col-role { width: 12%; }
.list-table-scroll-wrap .user-list-table .col-created { width: 15%; }
.list-table-scroll-wrap .user-list-table .col-aktion { width: 33%; }

/* Links */
a {
    color: #2563eb;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
    border-radius: 0.9rem;
    overflow: hidden;
}

th, td {
    padding: 0.75rem 0.95rem;
    text-align: left;
    font-size: 0.9rem;
}

th {
    background: #eff6ff;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: #4b5563;
    border-bottom: 1px solid #d1d5db;
}

tbody tr:nth-child(even) {
    background: #f9fafb;
}

tbody tr:nth-child(odd) {
    background: #ffffff;
}

.text-right {
    text-align: right;
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.15rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 500;
}

.badge-success {
    background: #dcfce7;
    color: #166534;
}

.badge-warning {
    background: #fef3c7;
    color: #92400e;
}

.badge-danger {
    background: #fee2e2;
    color: #991b1b;
}

.badge-info {
    background: #e0e7ff;
    color: #3730a3;
    font-size: 0.8rem;
}

/* Buttons */
.btn,
button.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.45rem 0.95rem;
    border-radius: 999px;
    border: none;
    background: linear-gradient(to right, #2563eb, #3b82f6);
    color: #ffffff;
    font-size: 0.85rem;
    font-weight: 500;
    font-family: inherit;
    text-decoration: none;
    cursor: pointer;
    box-shadow: 0 10px 25px rgba(37, 99, 235, 0.25);
    transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.08s ease;
    white-space: nowrap;
    appearance: none;
}

.btn:hover {
    text-decoration: none;
    transform: translateY(-1px);
    box-shadow: 0 16px 30px rgba(37, 99, 235, 0.35);
    filter: brightness(1.03);
}

.btn-primary {
    /* Erbt von .btn – primäre Aktion (Login, Setup) */
}

.btn-secondary,
button.btn-secondary {
    background: #e5e7eb !important;
    color: #111827 !important;
    box-shadow: none;
}

.btn-secondary:hover,
button.btn-secondary:hover {
    box-shadow: 0 6px 16px rgba(148, 163, 184, 0.35);
}

/* Page header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.2rem;
    gap: 1rem;
}

.page-header h2 {
    margin: 0;
    font-size: 1.25rem;
    color: #111827;
}

.muted {
    color: #6b7280;
    font-size: 0.9rem;
}

.template-info-block {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 0.5rem;
    padding: 0.6rem 0.9rem;
    margin-bottom: 1rem;
    font-size: 0.85rem;
    color: #1e40af;
}
.template-info-block code {
    background: #dbeafe;
    padding: 0.15rem 0.4rem;
    border-radius: 0.25rem;
    font-size: 0.8rem;
    margin-right: 0.25rem;
}

.invoice-import-hint {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 0.5rem;
    padding: 0.6rem 0.9rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
    color: #1e40af;
}

/* Messages */
.messages {
    list-style: none;
    padding: 0;
    margin: 0 0 1rem 0;
}

.messages li {
    padding: 0.6rem 0.9rem;
    border-radius: 0.75rem;
    margin-bottom: 0.4rem;
    font-size: 0.9rem;
}

.messages .success {
    background: #dcfce7;
    color: #166534;
}

.messages .error {
    background: #fee2e2;
    color: #991b1b;
}

.message {
    padding: 0.6rem 0.9rem;
    border-radius: 0.75rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}
.message.error {
    background: #fee2e2;
    color: #991b1b;
}
.message.success {
    background: #dcfce7;
    color: #166534;
}

/* Login / Setup page */
body.login-page {
    align-items: center;
    justify-content: center;
}
body.login-page main {
    flex: 0 0 auto;
    margin: 0;
}
.login-card {
    background: #ffffff;
    border-radius: 1.2rem;
    padding: 2rem;
    box-shadow: 0 18px 45px rgba(15, 23, 42, 0.08), 0 0 0 1px rgba(209, 213, 219, 0.7);
    max-width: 400px;
    width: 100%;
}
.login-card h1 {
    margin: 0 0 0.5rem 0;
    font-size: 1.5rem;
}
.login-subtitle {
    color: #6b7280;
    font-size: 0.95rem;
    margin: 0 0 1.5rem 0;
}
.login-card .form-group {
    margin-bottom: 1rem;
}
.login-card .btn {
    margin-top: 0.5rem;
}

/* Audit table */
.table-responsive {
    overflow-x: auto;
}
.audit-table {
    font-size: 0.85rem;
}
.audit-table th,
.audit-table td {
    padding: 0.4rem 0.6rem;
    white-space: nowrap;
}
.audit-details {
    white-space: normal;
    max-width: 220px;
}

/* Footer */
footer {
    text-align: center;
    padding: 0.8rem 0 1.5rem;
    font-size: 0.8rem;
    color: #9ca3af;
}

/* ========== Formulare ========== */
.form-group {
    margin-bottom: 1rem;
}

.form-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.form-row .form-group {
    flex: 1 1 160px;
    margin-bottom: 0;
}

.form-group label {
    display: block;
    margin-bottom: 0.25rem;
}

.customer-add-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.25rem;
    height: 1.25rem;
    margin-left: 0.25rem;
    font-size: 1rem;
    font-weight: 600;
    line-height: 1;
    color: #2563eb;
    text-decoration: none;
    border: 1px solid #2563eb;
    border-radius: 0.35rem;
    vertical-align: middle;
}
.customer-add-link:hover {
    background: #2563eb;
    color: #fff;
}

input[type="text"],
input[type="email"],
input[type="number"],
input[type="password"],
input[type="date"],
select,
textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border-radius: 0.75rem;
    border: 1px solid #d1d5db;
    background: #ffffff;
    color: #111827;
    font-size: 0.9rem;
    font-family: inherit;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="number"]:focus,
input[type="password"]:focus,
input[type="date"]:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* Kleine Inputs in Tabellen (Positionen) */
table input[type="text"],
table input[type="number"] {
    padding: 0.4rem 0.5rem;
    border-radius: 0.6rem;
}

.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    margin-bottom: 1rem;
}

.checkbox-label input[type="checkbox"] {
    width: auto;
}

.form-actions {
    margin-top: 1.2rem;
}

.form-actions .btn {
    margin-right: 0.5rem;
}

/* Positionen-Überschrift */
.invoice-positions-header {
    margin-bottom: 0.5rem;
}
.invoice-positions-header h3 {
    margin: 0;
}

/* Zeile „+ Position hinzufügen“ mit USt rechtsbündig */
.invoice-positions-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
}
.invoice-vat-inline {
    margin-left: auto;
    text-align: right;
    white-space: normal;
    max-width: 100%;
    min-width: 0; /* Flex-Child kann schrumpfen, Text bricht um */
}

.form-delete {
    display: inline-block;
    margin-left: 0.4rem;
}

/* Rechnungsübersicht Suche */
.invoice-search {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 1rem;
}

.invoice-search .search-input {
    width: 100%;
    max-width: 350px;
    padding: 0.45rem 0.75rem;
    border-radius: 0.75rem;
    border: 1px solid #d1d5db;
    background: #ffffff;
    color: #111827;
    font-size: 0.9rem;
}

.invoice-search .search-label {
    margin: 0;
    flex: 1;
    max-width: 280px;
}

.invoice-search button.btn-secondary,
.customer-list-table button.btn-secondary {
    background: #e5e7eb !important;
    color: #111827 !important;
    box-shadow: none;
}

/* Rechnungspositionen: dynamische Zeilen */
.invoice-item-actions {
    width: 3rem;
    text-align: center;
    vertical-align: middle;
}

.btn-remove-row {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: #fee2e2;
    color: #991b1b;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.btn-remove-row:hover {
    background: #fecaca;
    color: #b91c1c;
}

.btn-remove-row[style*="hidden"] {
    visibility: hidden;
}

/* Positionen-Tabelle: 80% / 10% / 10% + Aktion */
.invoice-items-table {
    table-layout: fixed;
}
.invoice-items-table .col-desc { width: 55%; }
.invoice-items-table .col-pa { width: 2.5rem; text-align: center; }
.invoice-items-table .col-qty { width: 10%; }
.invoice-items-table .col-price { width: 28%; }
.invoice-items-table .invoice-item-actions { width: 3rem; }
/* Detailansicht: 4 Spalten inkl. Gesamt */
.invoice-items-table.invoice-detail-items {
    table-layout: fixed;
    width: 100%;
}
.invoice-items-table.invoice-detail-items .col-desc,
.invoice-items-table.invoice-detail-items col.col-desc { width: 55%; }
.invoice-items-table.invoice-detail-items .col-qty,
.invoice-items-table.invoice-detail-items col.col-qty { width: 10%; }
.invoice-items-table.invoice-detail-items .col-price,
.invoice-items-table.invoice-detail-items col.col-price { width: 20%; }
.invoice-items-table.invoice-detail-items .col-total,
.invoice-items-table.invoice-detail-items col.col-total { width: 15%; min-width: 5rem; }
/* Summen-Block unter der Detail-Tabelle: volle Breite */
.invoice-detail-tfoot {
    width: 100%;
    margin-top: 0;
    padding: 0.75rem 0;
    border-top: 1px solid #e5e7eb;
}
.invoice-detail-tfoot-row {
    display: flex;
    justify-content: flex-end;
    gap: 2rem;
    align-items: center;
    padding: 0.25rem 0;
    font-size: 0.95rem;
}
.invoice-detail-tfoot-row span:last-child {
    font-weight: 600;
    min-width: 6rem;
    text-align: right;
    padding-right: 0.95rem; /* wie Positionstabelle th, td */
}
.invoice-detail-tfoot-total {
    font-weight: 700;
    font-size: 1.1rem;
    padding-top: 0.5rem;
    margin-top: 0.25rem;
    border-top: 1px solid #e2e8f0;
}
.invoice-detail-tfoot-hint {
    margin-top: 0.5rem;
    font-size: 0.85rem;
    font-style: italic;
    color: #6b7280;
}
.invoice-items-table textarea {
    width: 100%;
    min-height: 2.5em;
    padding: 0.4rem 0.5rem;
    border-radius: 0.6rem;
    border: 1px solid #d1d5db;
    font-size: 0.9rem;
    font-family: inherit;
    resize: vertical;
}
.invoice-items-table textarea:focus {
    outline: none;
    border-color: #2563eb;
}
/* Keine Hoch/Runter-Buttons bei Menge und Einzelpreis */
.invoice-items-table input[type="number"]::-webkit-outer-spin-button,
.invoice-items-table input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.invoice-items-table input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
    text-align: right;
    padding-right: 0.5rem;
}
.invoice-items-table .col-price input[type="number"] {
    width: 100%;
    min-width: 5rem;
    box-sizing: border-box;
}

/* Mitwachsende Textareas (Beschreibung, Zahlungsbedingungen) */
.textarea-auto-grow {
    overflow-y: hidden;
    resize: none;
    min-height: 2.5em;
}
.form-group .textarea-auto-grow {
    min-height: 3em;
}

/* Handy: Positionen als Karten, optimiert für Touch */
@media (max-width: 768px) {
    .invoice-items-table thead {
        display: none;
    }
    .invoice-items-table,
    .invoice-items-table tbody,
    .invoice-items-table tr,
    .invoice-items-table td,
    .invoice-items-table th {
        display: block;
    }
    .invoice-items-table tbody tr {
        border: 1px solid #e5e7eb;
        border-radius: 0.75rem;
        margin-bottom: 1rem;
        padding: 1rem;
        background: #ffffff;
        box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    }
    .invoice-items-table tbody td {
        width: 100% !important;
        padding: 0.5rem 0;
        border: none;
        background: transparent;
    }
    .invoice-items-table tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        font-size: 0.7rem;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: #6b7280;
        display: block;
        margin-bottom: 0.2rem;
    }
    .invoice-items-table tbody td.col-desc::before { content: "Beschreibung"; }
    .invoice-items-table tbody td.col-pa::before { content: "Pauschale"; }
    .invoice-items-table tbody td.col-qty::before { content: "Menge"; }
    .invoice-items-table tbody td.col-price::before { content: "Einzelpreis (€)"; }
    .invoice-items-table tbody td.col-total::before { content: "Gesamt"; }
    .invoice-items-table tbody td.invoice-item-actions::before {
        content: "";
        margin-bottom: 0;
    }
    .invoice-items-table tbody td.invoice-item-actions {
        padding-top: 0.5rem;
        padding-bottom: 0;
        text-align: left;
    }
    .invoice-items-table tbody textarea {
        min-height: 3.5em;
        font-size: 16px; /* iOS: Zoom vermeiden */
    }
    .invoice-items-table tbody input[type="number"] {
        min-height: 44px;
        font-size: 16px;
    }
    /* Formular: PA kompakt, Menge und Einzelpreis volle Breite */
    .invoice-items-table tbody td.col-pa {
        display: inline-block;
        width: auto !important;
        margin-right: 1rem;
        padding: 0.25rem 0;
    }
    .invoice-items-table tbody td.col-qty,
    .invoice-items-table tbody td.col-price {
        display: block;
        width: 100% !important;
        padding: 0.5rem 0;
    }
    .invoice-items-table tbody td.col-qty input[type="number"],
    .invoice-items-table tbody td.col-price input[type="number"] {
        width: 100%;
        box-sizing: border-box;
    }
    .invoice-items-table tbody td.col-pa { margin-right: 0.5rem; }
    .invoice-items-table tbody td.col-pa::before { display: inline; margin-right: 0.35rem; }
    .invoice-items-table tbody td.col-pa .pa-label { display: inline-flex; align-items: center; }
    .invoice-items-table tbody td.col-pa .pa-label input { width: 1.25rem; height: 1.25rem; }
    /* Detail-Ansicht: Beschreibung + Gesamt prominent, Menge/Preis kompakt */
    .invoice-items-table.invoice-detail-items tbody td.col-desc {
        font-weight: 500;
        padding-bottom: 0.25rem;
    }
    .invoice-items-table.invoice-detail-items tbody td.col-total {
        font-weight: 600;
        font-size: 1.05rem;
        color: #111827;
        padding-top: 0.25rem;
        border-top: 1px dashed #e5e7eb;
        margin-top: 0.25rem;
    }
    .invoice-items-table.invoice-detail-items tbody td.col-qty,
    .invoice-items-table.invoice-detail-items tbody td.col-price {
        display: inline-block;
        width: auto !important;
        margin-right: 1rem;
    }
    /* Summen-Block (invoice-detail-tfoot) auf Mobile */
    .invoice-detail-tfoot {
        margin-top: 1rem;
        padding: 1rem;
        background: #f8fafc;
        border-radius: 0.75rem;
        border-top: 2px solid #e5e7eb;
    }
    /* Position hinzufügen + USt: besser gestapelt */
    .invoice-positions-actions {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }
    .invoice-positions-actions .btn {
        width: 100%;
    }
    .invoice-vat-inline {
        margin-left: 0;
    }
    .btn-remove-row {
        min-width: 44px;
        min-height: 44px;
    }
}

/* ========== Rechnungs-Detail: PDF-Vorschau rechts ========== */
.invoice-detail-layout {
    display: grid;
    grid-template-columns: 1fr minmax(320px, 420px);
    gap: 1.5rem;
    align-items: start;
}
.invoice-detail-content {
    min-width: 0; /* Grid: verhindert Layout-Blowout durch Tabellen/overflow */
}

.invoice-detail-layout.pdf-panel-closed {
    grid-template-columns: 1fr;
}

.invoice-detail-layout.pdf-panel-closed .invoice-pdf-panel {
    display: none;
}

.invoice-pdf-panel {
    position: sticky;
    top: 5rem;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 1rem;
    overflow: hidden;
    min-height: 420px;
}

.invoice-pdf-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.6rem 0.9rem;
    background: #e2e8f0;
    font-size: 0.9rem;
    font-weight: 600;
    color: #334155;
}

.invoice-pdf-panel-actions {
    display: flex;
    gap: 0.4rem;
}

.btn-small {
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
}

.invoice-pdf-panel-frame {
    height: 72vh;
    min-height: 420px;
    background: #e2e8f0;
}

.invoice-pdf-panel-frame iframe {
    width: 100%;
    height: 100%;
    display: block;
    border: none;
}

/* Rechnungs-Detail: PDF herunterladen + E-Mail nebeneinander */
.invoice-detail-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: nowrap;
    margin-top: 1.5rem;
}
.invoice-detail-actions .btn,
.invoice-detail-actions form {
    flex-shrink: 0;
}
.invoice-detail-actions form.invoice-send-email-form,
.invoice-detail-actions .invoice-send-email-form {
    display: inline-flex;
    margin: 0;
    width: auto;
}

/* PDF-Historie: eigenes Layout, bricht Content-Breite nicht */
.invoice-pdf-history {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid #e5e7eb;
    width: 100%;
}
.invoice-pdf-history-title {
    margin: 0 0 0.75rem 0;
    font-size: 1rem;
}
.invoice-pdf-history-desc {
    margin: 0 0 0.75rem 0;
    font-size: 0.875rem;
}
.invoice-pdf-history-table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.invoice-pdf-history-table {
    width: 100%;
    table-layout: fixed;
}
.invoice-pdf-history-table th:nth-child(1),
.invoice-pdf-history-table td:nth-child(1) { width: 20%; }
.invoice-pdf-history-table th:nth-child(2),
.invoice-pdf-history-table td:nth-child(2) { width: 15%; }
.invoice-pdf-history-table th:nth-child(3),
.invoice-pdf-history-table td:nth-child(3) { width: 35%; }
.invoice-pdf-history-table th:nth-child(4),
.invoice-pdf-history-table td:nth-child(4) { width: 30%; }

/* Rechnungsübersicht: Haken zum Als-bezahlt-markieren */
.invoice-list-paid-form {
    display: inline-block;
    margin: 0 0 0 0.35rem;
    vertical-align: middle;
}
.btn-mark-paid {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    padding: 0;
    border: none;
    border-radius: 999px;
    background: linear-gradient(135deg, #22c55e, #16a34a);
    color: #ffffff;
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(34, 197, 94, 0.35);
    transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.08s ease;
}
.btn-mark-paid:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(34, 197, 94, 0.45);
    filter: brightness(1.05);
}

/* Rechnungs-Detail: Anordnung wie PDF (Empfänger, Titelzeile, Meta, Positionen, Zahlung) */
.invoice-detail-doc {
    margin-top: 1rem;
}
.invoice-detail-recipient {
    margin-bottom: 1.25rem;
    line-height: 1.5;
}
.invoice-detail-title-row {
    width: 100%;
    margin-bottom: 1.25rem;
    border: none;
}
.invoice-detail-title-row td {
    border: none;
    padding: 0;
    background: none;
}
.invoice-detail-heading {
    font-size: 1.25rem;
    font-weight: bold;
    margin: 0 0 0.2rem 0;
}
.invoice-detail-number {
    font-size: 1rem;
    color: #4b5563;
}
.invoice-detail-date {
    font-size: 1rem;
}
.invoice-detail-meta {
    margin-bottom: 0.75rem;
    font-size: 0.95rem;
}
.invoice-detail-positions-title {
    margin: 1.25rem 0 0.5rem 0;
    font-size: 1.1rem;
}
.invoice-detail-payment {
    margin-top: 1.25rem;
    margin-bottom: 0;
    font-size: 0.9rem;
    line-height: 1.5;
    color: #4b5563;
}
@media (max-width: 900px) {
    .invoice-detail-layout {
        grid-template-columns: 1fr;
    }
    .invoice-detail-layout .invoice-pdf-panel {
        position: static;
    }
    .invoice-detail-layout.pdf-panel-closed .invoice-pdf-panel {
        display: none;
    }
}

/* ========== Mobile / kleine Bildschirme ========== */
@media (max-width: 768px) {
    body {
        overflow-x: hidden;
    }

    main {
        margin: 1rem auto;
        padding: 0 1rem 1.5rem;
    }

    .card {
        padding: 1rem;
    }

    header {
        padding: 0.75rem 1rem;
        flex-wrap: wrap;
        gap: 0;
        position: relative;
    }
    .header-inner {
        flex-wrap: wrap;
        gap: 0.5rem;
        flex: 1 1 auto;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }
    header h1 {
        font-size: 1.1rem;
    }
    .header-inner {
        position: relative;
        z-index: 20;
    }
    .header-burger {
        display: flex;
        order: 2;
        z-index: 12;
        position: relative;
        cursor: pointer;
    }
    body.nav-open .header-burger-bar:nth-child(1) {
        transform: translateY(7px) rotate(45deg);
    }
    body.nav-open .header-burger-bar:nth-child(2) {
        opacity: 0;
    }
    body.nav-open .header-burger-bar:nth-child(3) {
        transform: translateY(-7px) rotate(-45deg);
    }
    .header-nav {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        flex-direction: column;
        background: #ffffff;
        box-shadow: 0 8px 24px rgba(15, 23, 42, 0.15);
        padding: 1rem;
        gap: 0;
        z-index: 11;
        border-top: 1px solid #e5e7eb;
        max-height: calc(100vh - 60px);
        overflow-y: auto;
    }
    .header-nav a {
        display: block;
        padding: 0.75rem 1rem;
        border-radius: 0.5rem;
        font-size: 1rem;
        white-space: nowrap;
    }
    .header-nav a:hover {
        background: #f3f4f6;
    }
    body.nav-open .header-nav {
        display: flex;
    }
    .header-logo,
    header > span {
        flex: 1 1 100%;
        display: block;
        margin-left: auto;
        margin-right: auto;
        text-align: center;
    }
    .header-logo {
        height: 3rem;
        max-height: 60px;
    }
    header > span {
        font-size: 0.85rem;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
        margin-bottom: 1rem;
    }
    .page-header h2 {
        font-size: 1.15rem;
    }

    .list-page-sticky-top {
        margin: -1rem -1rem 0 -1rem;
        padding: 1rem;
    }

    .invoice-search {
        flex-wrap: wrap;
        gap: 0.5rem;
        margin-bottom: 0.75rem;
    }
    .invoice-search .search-label,
    .invoice-search .search-input {
        max-width: 100%;
        width: 100%;
    }

    /* Rechnungs-/Anbotsliste: Karten statt Tabelle, kein horizontales Scrollen */
    .list-table-scroll-wrap {
        margin-top: 0.75rem;
        max-height: none;
        overflow: visible;
        -webkit-overflow-scrolling: touch;
        border-radius: 0.5rem;
        border: none;
    }
    .list-table-scroll-wrap .invoice-list-table {
        min-width: 0;
        display: block;
    }
    .list-table-scroll-wrap .invoice-list-table colgroup,
    .list-table-scroll-wrap .invoice-list-table thead {
        display: none;
    }
    .list-table-scroll-wrap .invoice-list-table tbody,
    .list-table-scroll-wrap .invoice-list-table tr,
    .list-table-scroll-wrap .invoice-list-table td {
        display: block;
        width: 100%;
    }
    .list-table-scroll-wrap .invoice-list-table tbody tr {
        border: 1px solid #e5e7eb;
        border-radius: 0.75rem;
        margin-bottom: 0.75rem;
        padding: 1rem;
        background: #ffffff;
        box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    }
    .list-table-scroll-wrap .invoice-list-table td {
        padding: 0.35rem 0;
        border: none;
        font-size: 0.9rem;
    }
    .list-table-scroll-wrap .invoice-list-table td.col-nr {
        padding-top: 0;
        padding-bottom: 0.25rem;
        width: 100%;
    }
    .list-table-scroll-wrap .invoice-list-table td.col-nr a {
        font-weight: 600;
        font-size: 1rem;
    }
    .list-table-scroll-wrap .invoice-list-table td.col-kunde {
        font-weight: 500;
        width: 100%;
        max-width: none;
        overflow: visible;
        white-space: normal;
    }
    .list-table-scroll-wrap .invoice-list-table td.col-betreff {
        display: block !important;
        font-size: 0.85rem;
        color: #6b7280;
        width: 100%;
        max-width: none;
        overflow: visible;
        white-space: normal;
    }
    .list-table-scroll-wrap .invoice-list-table td.col-betreff::before {
        content: "Betreff: ";
        font-weight: 600;
        color: inherit;
    }
    .list-table-scroll-wrap .invoice-list-table td.col-bauvorhaben {
        font-size: 0.85rem;
        color: #6b7280;
        width: 100%;
    }
    .list-table-scroll-wrap .invoice-list-table td.col-bauvorhaben::before {
        content: "BV: ";
        font-weight: 600;
        color: inherit;
    }
    .list-table-scroll-wrap .invoice-list-table td.col-datum,
    .list-table-scroll-wrap .invoice-list-table td.col-status {
        display: inline-block;
        margin-right: 1rem;
        padding: 0.2rem 0;
        width: 100%;
    }
    .list-table-scroll-wrap .invoice-list-table td.col-status .invoice-list-paid-form {
        display: inline;
    }
    .list-table-scroll-wrap .invoice-list-table td.col-pdf-email {
        font-size: 0.8rem;
        width: 100%;
        max-width: none;
        overflow: visible;
        white-space: normal;
    }
    .list-table-scroll-wrap .invoice-list-table td.col-pdf-email .badge {
        font-size: 0.7rem;
        padding: 0.2rem 0.4rem;
    }
    .list-table-scroll-wrap .invoice-list-table td.col-aktion {
        padding-top: 0.75rem;
        margin-top: 0.5rem;
        border-top: 1px dashed #e5e7eb;
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        gap: 0.5rem;
        align-items: center;
        width: 100%;
    }
    .list-table-scroll-wrap .invoice-list-table td.col-aktion .btn {
        flex: 0 0 auto;
        white-space: nowrap;
    }

    /* Kundenliste: Karten auf Mobile */
    .list-table-scroll-wrap .customer-list-table {
        min-width: 0;
        display: block;
    }
    .list-table-scroll-wrap .customer-list-table colgroup,
    .list-table-scroll-wrap .customer-list-table thead {
        display: none;
    }
    .list-table-scroll-wrap .customer-list-table tbody,
    .list-table-scroll-wrap .customer-list-table tr,
    .list-table-scroll-wrap .customer-list-table td {
        display: block;
        width: 100%;
    }
    .list-table-scroll-wrap .customer-list-table tbody tr {
        border: 1px solid #e5e7eb;
        border-radius: 0.75rem;
        margin-bottom: 0.75rem;
        padding: 1rem;
        background: #ffffff;
        box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    }
    .list-table-scroll-wrap .customer-list-table td {
        padding: 0.35rem 0;
        border: none;
        font-size: 0.9rem;
    }
    .list-table-scroll-wrap .customer-list-table td.col-name {
        font-weight: 600;
        font-size: 1rem;
        padding-bottom: 0.25rem;
        width: 100%;
    }
    .list-table-scroll-wrap .customer-list-table td.col-email {
        font-size: 0.9rem;
        width: 100%;
    }
    .list-table-scroll-wrap .customer-list-table td.col-address {
        font-size: 0.85rem;
        color: #6b7280;
        width: 100%;
    }
    .list-table-scroll-wrap .customer-list-table td.col-status {
        display: inline-block;
        padding: 0.2rem 0;
        width: 100%;
    }
    .list-table-scroll-wrap .customer-list-table td.col-aktion {
        padding-top: 0.75rem;
        margin-top: 0.5rem;
        border-top: 1px dashed #e5e7eb;
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.5rem;
        align-items: center;
        width: 100%;
    }
    .list-table-scroll-wrap .customer-list-table td.col-aktion .btn,
    .list-table-scroll-wrap .customer-list-table td.col-aktion form {
        flex: 0 0 auto;
        white-space: nowrap;
    }
    .list-table-scroll-wrap .customer-list-table td.col-aktion form {
        display: inline-flex !important;
    }

    /* Benutzerliste: Karten auf Mobile */
    .list-table-scroll-wrap .user-list-table {
        min-width: 0;
        display: block;
    }
    .list-table-scroll-wrap .user-list-table colgroup,
    .list-table-scroll-wrap .user-list-table thead {
        display: none;
    }
    .list-table-scroll-wrap .user-list-table tbody,
    .list-table-scroll-wrap .user-list-table tr,
    .list-table-scroll-wrap .user-list-table td {
        display: block;
        width: 100%;
    }
    .list-table-scroll-wrap .user-list-table tbody tr {
        border: 1px solid #e5e7eb;
        border-radius: 0.75rem;
        margin-bottom: 0.75rem;
        padding: 1rem;
        background: #ffffff;
        box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    }
    .list-table-scroll-wrap .user-list-table td {
        padding: 0.35rem 0;
        border: none;
        font-size: 0.9rem;
    }
    .list-table-scroll-wrap .user-list-table td.col-name {
        font-weight: 600;
        font-size: 1rem;
        padding-bottom: 0.25rem;
        width: 100%;
    }
    .list-table-scroll-wrap .user-list-table td.col-role {
        display: inline-block;
        padding: 0.2rem 0;
        width: 100%;
    }
    .list-table-scroll-wrap .user-list-table td.col-created {
        font-size: 0.85rem;
        color: #6b7280;
        width: 100%;
    }
    .list-table-scroll-wrap .user-list-table td.col-aktion {
        padding-top: 0.75rem;
        margin-top: 0.5rem;
        border-top: 1px dashed #e5e7eb;
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.5rem;
        align-items: center;
        width: 100%;
    }
    .list-table-scroll-wrap .user-list-table td.col-aktion .btn {
        flex: 0 0 auto;
        white-space: nowrap;
    }

    .list-page-float-bar,
    .invoice-form-submit-bar {
        margin: 1rem -1rem -1rem -1rem;
        padding: 0.75rem 1rem;
    }
    .list-page-float-bar {
        display: none;
    }

    .btn {
        min-height: 44px;
        padding: 0.5rem 0.85rem;
        font-size: 0.85rem;
    }

    .invoice-detail-actions {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    /* PDF-Historie: Empfänger-Spalte ausblenden, damit es auf Mobile passt */
    .invoice-pdf-history-table th:nth-child(3),
    .invoice-pdf-history-table td:nth-child(3) {
        display: none;
    }
    .invoice-pdf-history-table th:nth-child(1),
    .invoice-pdf-history-table td:nth-child(1) { width: 30%; }
    .invoice-pdf-history-table th:nth-child(2),
    .invoice-pdf-history-table td:nth-child(2) { width: 25%; }
    .invoice-pdf-history-table th:nth-child(4),
    .invoice-pdf-history-table td:nth-child(4) { width: 45%; }

    /* iOS: Zoom bei Fokus vermeiden (Inputs mind. 16px) */
    input[type="text"],
    input[type="email"],
    input[type="number"],
    input[type="password"],
    input[type="date"],
    input[type="search"],
    select,
    textarea {
        font-size: 16px;
    }

    .btn-mark-paid {
        min-width: 44px;
        min-height: 44px;
    }
}

@media (max-width: 480px) {
    main {
        padding: 0 0.75rem 1rem;
    }
    .card {
        padding: 0.75rem;
    }
    .list-page-sticky-top {
        margin: -0.75rem -0.75rem 0 -0.75rem;
        padding: 0.75rem;
    }
    .list-page-float-bar,
    .invoice-form-submit-bar {
        margin: 0.75rem -0.75rem -0.75rem -0.75rem;
        padding: 0.6rem 0.75rem;
    }
    /* Positionen: noch kompakter auf sehr kleinen Displays */
    .invoice-items-table tbody tr {
        padding: 0.75rem;
    }
    .invoice-items-table tbody td.col-pa,
    .invoice-items-table tbody td.col-qty,
    .invoice-items-table tbody td.col-price {
        margin-right: 0.75rem;
    }
    .invoice-detail-tfoot {
        padding: 0.75rem;
    }
}

/* Drucken: Importierte Rechnungen */
@media print {
    .no-print {
        display: none !important;
    }
    header, footer, .list-page-float-bar, .list-page-sticky-top .invoice-search {
        display: none !important;
    }
    .imported-invoices-page {
        padding: 0;
    }
    .imported-invoices-header .imported-invoices-actions {
        display: none !important;
    }
    .imported-invoices-table .col-links {
        display: none !important;
    }
    .print-checkbox {
        font-size: 1rem;
    }
}

