:root {
    --bg1: #e8f4f8;
    --bg2: #d4e9f7;
    --bg3: #c8e3f5;
    --ink: #2c3e50;
    --head: #34495e;
    --head2: #2c3e50;
    --accent: #3498db;
    --accent2: #2980b9;
    --danger: #c0392b;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    color: var(--ink);
    min-height: 100vh;
    padding-bottom: 28px;
    background: linear-gradient(135deg, var(--bg1) 0%, var(--bg2) 35%, var(--bg3) 65%, #f0f4f8 100%);
}

.app-footer {
    position: fixed;
    left: 10px;
    bottom: 8px;
    font-size: 0.75rem;
    color: rgba(44, 62, 80, 0.78);
    z-index: 25;
    pointer-events: none;
}

.floating-backup-actions {
    position: fixed;
    right: 16px;
    bottom: 56px;
    z-index: 26;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.floating-backup-actions .btn {
    min-width: 240px;
    text-align: center;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 12px 18px;
    color: #fff;
    background: linear-gradient(135deg, var(--head) 0%, var(--head2) 100%);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
}

.topbar-left {
    flex: 0 0 auto;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1 1 auto;
    min-width: 0;
    flex-wrap: nowrap;
    justify-content: flex-end;
    overflow-x: auto;
    white-space: nowrap;
}

.topbar-right .btn {
    max-width: 100%;
    padding: 8px 10px;
    font-size: 0.82rem;
}

.user-chip {
    display: inline-flex;
    align-items: center;
    padding: 8px 10px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.45);
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
    font-size: 0.85rem;
}

.topbar h1 {
    margin: 0;
    font-size: 1.4rem;
}

.topbar p {
    margin: 2px 0 0;
    font-size: 0.9rem;
    opacity: 0.9;
}

.session-meta-bar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    padding: 8px 18px 0;
}

.layout {
    max-width: 1400px;
    margin: 0 auto;
    padding: 16px;
    display: grid;
    gap: 16px;
}

.card {
    background: rgba(255, 255, 255, 0.56);
    border: 1px solid rgba(52, 152, 219, 0.25);
    border-radius: 16px;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 24px rgba(52, 152, 219, 0.12);
    padding: 14px;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(140px, 1fr));
    gap: 10px;
}

.stat {
    padding: 10px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.5);
    border: 1px solid rgba(52, 152, 219, 0.16);
}

.stat span {
    display: block;
    font-size: 0.82rem;
    color: #4f6b81;
}

.stat-year-label {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.stat-year-select {
    border: 1px solid rgba(52, 152, 219, 0.35);
    border-radius: 8px;
    padding: 2px 8px;
    background: rgba(255, 255, 255, 0.88);
    color: #2c3e50;
    font-size: 0.82rem;
}

.stat-year-select:disabled {
    opacity: 0.75;
}

.stat strong {
    font-size: 1.3rem;
}

.two-col {
    display: grid;
    grid-template-columns: 1.5fr 1fr;
    gap: 16px;
}

.stack {
    display: grid;
    gap: 16px;
}

.action-card {
    display: grid;
    align-content: start;
}

.reminder-card {
    transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.reminder-card.has-overdue {
    border-color: rgba(192, 57, 43, 0.55);
    box-shadow: 0 10px 24px rgba(192, 57, 43, 0.2);
    background: linear-gradient(180deg, rgba(255, 246, 246, 0.92) 0%, rgba(255, 255, 255, 0.72) 100%);
}

.reminder-card.has-due {
    border-color: rgba(230, 126, 34, 0.5);
    box-shadow: 0 10px 24px rgba(230, 126, 34, 0.16);
    background: linear-gradient(180deg, rgba(255, 250, 241, 0.92) 0%, rgba(255, 255, 255, 0.72) 100%);
}

.action-card-body {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 12px;
}

.compact-stat {
    min-width: 130px;
}

.status-pill {
    display: inline-block;
    border-radius: 999px;
    padding: 3px 8px;
    font-size: 0.74rem;
    border: 1px solid transparent;
}

.status-pill.overdue {
    color: #8f1f1f;
    background: rgba(192, 57, 43, 0.14);
    border-color: rgba(192, 57, 43, 0.35);
}

.status-pill.due {
    color: #8a4f00;
    background: rgba(230, 126, 34, 0.16);
    border-color: rgba(230, 126, 34, 0.36);
}

.status-pill.done {
    color: #1f5b37;
    background: rgba(46, 204, 113, 0.16);
    border-color: rgba(39, 174, 96, 0.3);
}

.status-pill.none {
    color: #4f6b81;
    background: rgba(52, 152, 219, 0.1);
    border-color: rgba(52, 152, 219, 0.24);
}

.note-cell {
    white-space: normal;
    min-width: 260px;
    max-width: 420px;
}

.card-head h2,
.card-head h3 {
    margin: 0;
}

.card-head p {
    margin: 4px 0 0;
    color: #4f6b81;
    font-size: 0.9rem;
}

.table-wrap {
    overflow: auto;
    max-height: 340px;
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead th {
    position: sticky;
    top: 0;
    background: #eff7fd;
    text-align: left;
    font-size: 0.82rem;
    color: #4f6b81;
}

th,
td {
    padding: 10px;
    border-bottom: 1px solid rgba(52, 152, 219, 0.14);
    white-space: nowrap;
}

tbody tr {
    cursor: pointer;
}

tbody tr:hover {
    background: rgba(52, 152, 219, 0.1);
}

.form-grid {
    display: grid;
    gap: 8px;
}

.form-grid.three {
    grid-template-columns: repeat(3, minmax(120px, 1fr));
}

.form-span-all {
    grid-column: 1 / -1;
}

label {
    display: grid;
    gap: 4px;
    font-size: 0.82rem;
    color: #456;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.86rem;
}

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
}

input,
select,
textarea,
button {
    font: inherit;
}

input,
select,
textarea {
    border: 1px solid rgba(52, 152, 219, 0.35);
    border-radius: 10px;
    padding: 8px 10px;
    background: rgba(255, 255, 255, 0.82);
}

textarea {
    min-height: 64px;
}

.btn {
    border: 0;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent2) 100%);
    color: #fff;
    padding: 10px 14px;
    cursor: pointer;
    font-weight: 600;
}

.btn:hover {
    filter: brightness(1.06);
}

.btn-secondary {
    background: linear-gradient(135deg, #607d8b 0%, #455a64 100%);
}

.help {
    margin: 8px 0 0;
    color: #4f6b81;
    font-size: 0.85rem;
}

.tenant-persons-block {
    display: grid;
    gap: 10px;
    padding: 10px;
    border: 1px solid rgba(52, 152, 219, 0.25);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.6);
}

.tenant-persons-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.tenant-persons-list {
    display: grid;
    gap: 8px;
}

.tenant-person-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(140px, 1fr));
    gap: 8px;
    align-items: end;
}

.tenant-person-remove {
    grid-column: 1 / -1;
    justify-self: start;
}

@media (max-width: 980px) {
    .tenant-person-row {
        grid-template-columns: repeat(2, minmax(140px, 1fr));
    }

    .tenant-person-remove {
        grid-column: 1 / -1;
        justify-self: start;
    }
}

@media (max-width: 640px) {
    .tenant-person-row {
        grid-template-columns: 1fr;
    }
}

.simple-list {
    margin: 0;
    padding-left: 18px;
    max-height: 220px;
    overflow: auto;
}

.simple-list li {
    margin-bottom: 6px;
}

#tenantList {
    list-style: none;
    padding-left: 0;
}

.tenant-entry {
    border: 1px solid rgba(52, 152, 219, 0.22);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.72);
    padding: 10px 12px;
    align-items: flex-start;
}

.tenant-entry-main {
    display: grid;
    gap: 6px;
    min-width: 0;
}

.tenant-entry-name {
    color: #243849;
    font-size: 0.98rem;
}

.tenant-entry-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.tenant-chip {
    display: inline-block;
    font-size: 0.76rem;
    border-radius: 999px;
    padding: 4px 8px;
    border: 1px solid rgba(52, 152, 219, 0.28);
    color: #1e5e8b;
    background: rgba(52, 152, 219, 0.1);
}

.tenant-chip-unit {
    color: #2f5f3a;
    border-color: rgba(46, 125, 50, 0.28);
    background: rgba(76, 175, 80, 0.12);
}

.tenant-list-item {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: center;
}

.list-actions {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.mini-link-danger {
    color: #8f1f1f;
    background: rgba(192, 57, 43, 0.12);
    border-color: rgba(192, 57, 43, 0.3);
}

.mini-link-danger:hover {
    background: rgba(192, 57, 43, 0.2);
}

.mini-link {
    display: inline-block;
    font-size: 0.78rem;
    text-decoration: none;
    border-radius: 8px;
    padding: 4px 8px;
    color: #1e5e8b;
    background: rgba(52, 152, 219, 0.12);
    border: 1px solid rgba(52, 152, 219, 0.28);
}

.mini-link:hover {
    background: rgba(52, 152, 219, 0.2);
}

.provider-group-row td {
    background: rgba(52, 152, 219, 0.16);
    color: #204c69;
    font-weight: 700;
    border-top: 1px solid rgba(52, 152, 219, 0.3);
}

.modal {
    position: fixed;
    inset: 0;
    background: rgba(44, 62, 80, 0.35);
    display: grid;
    place-items: center;
    padding: 14px;
    z-index: 30;
}

.modal.hidden {
    display: none;
}

.modal-box {
    width: min(540px, 100%);
    background: #f7fcff;
    border: 1px solid rgba(52, 152, 219, 0.35);
    border-radius: 14px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.18);
    padding: 14px;
}

.modal-box-wide {
    width: min(1100px, 96vw);
    max-height: 92vh;
    overflow: auto;
}

.modal-box-contract {
    width: min(1240px, 97vw);
}

.auth-modal-box {
    width: min(420px, 92vw);
}

.modal-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.report-summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(140px, 1fr));
    gap: 10px;
    margin-bottom: 12px;
}

.report-block {
    margin-bottom: 12px;
}

.report-block h4 {
    margin: 0 0 8px;
    color: #2c3e50;
}

.modal-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.modal-form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 8px;
}

.owner-toolbar {
    align-items: end;
    margin-bottom: 10px;
}

.owner-toolbar-actions {
    margin-top: 0;
    justify-content: flex-start;
}

.modal-form-actions-spread {
    justify-content: space-between;
    align-items: center;
}

.adjustment-modal-box {
    width: min(640px, 96vw);
    border: 1px solid rgba(52, 152, 219, 0.32);
    background: linear-gradient(180deg, rgba(244, 252, 255, 0.98) 0%, rgba(237, 248, 255, 0.96) 100%);
}

.adjustment-modal-intro {
    margin: 0 0 12px;
    padding: 10px 12px;
    border: 1px solid rgba(52, 152, 219, 0.2);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.65);
}

.adjustment-form {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
    gap: 10px;
}

.adjustment-form label {
    padding: 8px 10px;
    border: 1px solid rgba(52, 152, 219, 0.16);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.7);
}

.adjustment-modal-actions {
    margin-top: 4px;
}

.adjustment-modal-actions .btn {
    min-width: 220px;
}

.icon-btn {
    border: none;
    background: transparent;
    color: #34495e;
    font-size: 1.2rem;
    cursor: pointer;
}

.preview {
    border: 1px dashed rgba(52, 152, 219, 0.5);
    border-radius: 10px;
    padding: 8px;
    background: #eef8ff;
    color: #31546b;
    white-space: pre-line;
}

.documents-preview {
    margin-top: 12px;
    border: 1px solid rgba(52, 152, 219, 0.28);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.72);
    padding: 12px;
}

.documents-preview h4 {
    margin: 0 0 8px;
    color: #1e3d5b;
}

.document-preview-image {
    max-width: 100%;
    max-height: 58vh;
    border-radius: 8px;
    border: 1px solid rgba(52, 152, 219, 0.22);
    background: #fff;
}

.document-preview-frame {
    width: 100%;
    min-height: 62vh;
    border: 1px solid rgba(52, 152, 219, 0.24);
    border-radius: 8px;
    background: #fff;
}

.document-preview-text {
    margin: 0;
    padding: 10px;
    border-radius: 8px;
    background: #f3f9ff;
    border: 1px solid rgba(52, 152, 219, 0.18);
    white-space: pre-wrap;
    font-family: "Consolas", "Courier New", monospace;
    font-size: 0.86rem;
}

.contract-frame {
    width: 100%;
    min-height: 72vh;
    border: 1px solid rgba(52, 152, 219, 0.24);
    border-radius: 12px;
    background: #fff;
}

.toast {
    position: fixed;
    right: 16px;
    bottom: 16px;
    max-width: 420px;
    background: #2c3e50;
    color: #fff;
    border-radius: 10px;
    padding: 10px 12px;
    z-index: 40;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
}

.toast.error {
    background: var(--danger);
}

.toast.hidden {
    display: none;
}

/* ---- Mietobjekte-Modal ---- */
.property-manager-layout {
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 16px;
    min-height: 380px;
}

.property-manager-list {
    border-right: 1px solid rgba(52, 152, 219, 0.2);
    padding-right: 12px;
    overflow-y: auto;
}

.property-manager-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.property-manager-table th {
    text-align: left;
    padding: 4px 6px;
    font-size: 0.78rem;
    color: #5b7c99;
    border-bottom: 1px solid rgba(52, 152, 219, 0.2);
}

.property-manager-table td {
    padding: 6px 6px;
    border-bottom: 1px solid rgba(52, 152, 219, 0.08);
    vertical-align: middle;
}

.property-manager-row {
    cursor: default;
}

.property-manager-row:hover {
    background: rgba(52, 152, 219, 0.07);
}

.property-manager-row.active-row {
    background: rgba(52, 152, 219, 0.15);
    font-weight: 600;
}

.property-manager-edit {
    overflow-y: auto;
    padding-left: 4px;
}

.property-manager-edit > h4 {
    margin: 0 0 10px;
    color: #1e3d5b;
    font-size: 1rem;
}

.units-section {
    margin-top: 16px;
    border-top: 1px solid rgba(52, 152, 219, 0.2);
    padding-top: 12px;
}

.units-section > h4 {
    margin: 0 0 8px;
    font-size: 0.9rem;
    color: #2c3e50;
}

.unit-add-form {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid rgba(52, 152, 219, 0.12);
}

.unit-form-title {
    margin: 0 0 8px;
    font-size: 0.85rem;
    color: #2c3e50;
    font-weight: 600;
}

.unit-rent-history-box {
    border: 1px solid rgba(52, 152, 219, 0.2);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.7);
    padding: 10px;
}

.unit-rent-history-box h5 {
    margin: 0 0 8px;
    font-size: 0.82rem;
    color: #2c3e50;
}

.payment-history-toolbar {
    margin-bottom: 10px;
    align-items: end;
    grid-template-columns: repeat(4, minmax(120px, 1fr));
}

.payment-history-toolbar .modal-form-actions {
    grid-column: 1 / -1;
}

/* ---- Einheiten-Status-Badges ---- */
.unit-status {
    display: inline-block;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 10px;
    margin-left: 6px;
    vertical-align: middle;
    white-space: nowrap;
}

.unit-status--free {
    background: rgba(39, 174, 96, 0.14);
    color: #1a7a3e;
}

.unit-status--occupied {
    background: rgba(231, 76, 60, 0.13);
    color: #c0392b;
}

.unit-status--notice {
    background: rgba(243, 156, 18, 0.15);
    color: #b7770d;
}

/* ---- Papierkorb-Badge ---- */
.trash-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    background: var(--danger);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0 4px;
    margin-left: 2px;
    vertical-align: middle;
}

.trash-badge.hidden {
    display: none;
}

@media (max-width: 1100px) {
    .two-col {
        grid-template-columns: 1fr;
    }

    .property-manager-layout {
        grid-template-columns: 1fr;
    }

    .property-manager-list {
        border-right: none;
        border-bottom: 1px solid rgba(52, 152, 219, 0.2);
        padding-right: 0;
        padding-bottom: 12px;
        max-height: 200px;
    }

    .form-grid.three {
        grid-template-columns: repeat(2, minmax(120px, 1fr));
    }

    .summary-grid {
        grid-template-columns: repeat(2, minmax(120px, 1fr));
    }

    .modal-form-actions-spread {
        justify-content: flex-end;
        flex-wrap: wrap;
    }
}

@media (min-width: 768px) and (max-width: 1180px) {
    .topbar {
        align-items: flex-start;
    }

    .topbar-right {
        flex-wrap: wrap;
        overflow-x: visible;
        white-space: normal;
        gap: 8px;
        row-gap: 8px;
    }

    .topbar-right .btn {
        min-height: 44px;
        padding: 10px 12px;
    }

    .floating-backup-actions {
        right: 12px;
        bottom: 52px;
    }

    .floating-backup-actions .btn {
        min-width: 210px;
        min-height: 44px;
    }

    .table-wrap {
        max-height: 46vh;
    }
}

@media (min-width: 820px) and (max-width: 1180px) and (orientation: landscape) {
    .topbar {
        display: grid;
        grid-template-columns: 1fr;
        align-items: start;
        gap: 10px;
    }

    .topbar-left {
        width: 100%;
    }

    .topbar-right {
        width: 100%;
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
        gap: 8px;
    }

    .topbar-right .btn {
        width: 100%;
        min-height: 44px;
        padding: 10px;
        font-size: 0.9rem;
    }
}

@media (max-width: 640px) {
    .topbar {
        align-items: flex-start;
    }

    .form-grid.three,
    .summary-grid {
        grid-template-columns: 1fr;
    }

    .report-summary-grid {
        grid-template-columns: 1fr;
    }

    .action-card-body,
    .modal-form-actions,
    .modal-form-actions-spread {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
    }

    .topbar-right {
        width: 100%;
        display: grid;
        grid-template-columns: repeat(2, minmax(130px, 1fr));
        align-items: stretch;
        gap: 8px;
    }

    .topbar-right .btn {
        width: 100%;
        min-height: 42px;
        padding: 9px 10px;
        font-size: 0.88rem;
    }

    .floating-backup-actions {
        right: 10px;
        left: 10px;
        bottom: 44px;
    }

    .floating-backup-actions .btn {
        min-width: 0;
        width: 100%;
    }

    .adjustment-form {
        grid-template-columns: 1fr;
    }

    .adjustment-modal-actions .btn {
        min-width: 0;
        width: 100%;
    }
}

@media (max-width: 430px) {
    .topbar-right {
        grid-template-columns: 1fr;
    }
}

@media print {
    @page {
        margin: 12mm 10mm 18mm 10mm;
    }

    body {
        padding-bottom: 24mm !important;
    }

    body > * {
        display: none !important;
    }

    .app-footer {
        display: block !important;
        left: 10mm !important;
        bottom: 6mm !important;
    }

    #reportModal {
        position: static !important;
        inset: auto !important;
        background: #fff !important;
        padding: 0 !important;
        margin: 0 !important;
        display: block !important;
    }

    #reportModal.hidden {
        display: block !important;
    }

    #reportModal .modal-box {
        width: 100% !important;
        max-height: none !important;
        overflow: visible !important;
        border: none !important;
        box-shadow: none !important;
        border-radius: 0 !important;
        padding: 0 0 24mm !important;
    }

    #reportModal .modal-head {
        margin-bottom: 10px;
    }

    #reportModal .modal-actions,
    #reportModal .icon-btn {
        display: none !important;
    }
}
