:root {
    --blue: #00539b;
    --blue-dark: #003f78;
    --line: #333;
    --muted: #68717a;
    --page-bg: #e9edf1;
    --card-bg: #fff;
}

* {
    box-sizing: border-box;
}

html {
    font-family:
        Arial,
        Helvetica,
        sans-serif;
    color: #111;
    background: var(--page-bg);
}

body {
    margin: 0;
}

button,
input,
select,
textarea {
    font: inherit;
}

a {
    color: var(--blue);
}

.app-header {
    height: 64px;
    padding: 0 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--blue);
    color: white;
}

.app-brand {
    color: white;
    text-decoration: none;
    font-size: 24px;
    font-weight: 800;
    letter-spacing: 0.08em;
}

.app-header nav {
    display: flex;
    align-items: center;
    gap: 22px;
}

.app-header nav a,
.app-header nav button {
    color: white;
    background: none;
    border: 0;
    text-decoration: none;
    cursor: pointer;
}

.app-header form {
    margin: 0;
}

.content-shell {
    width: min(1180px, calc(100% - 40px));
    margin: 38px auto;
}

.page-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.page-heading h1 {
    margin: 0 0 5px;
}

.page-heading p {
    margin: 0;
    color: var(--muted);
}

.invoice-list {
    display: grid;
    gap: 18px;
}

.invoice-card {
    background: white;
    padding: 24px;
    border-radius: 8px;
    box-shadow: 0 3px 12px rgb(0 0 0 / 8%);
    display: flex;
    justify-content: space-between;
    gap: 30px;
}

.invoice-card h2 {
    margin: 10px 0 7px;
    font-size: 20px;
}

.invoice-card p {
    margin: 0;
    color: var(--muted);
}

.invoice-card-values {
    display: flex;
    align-items: center;
    gap: 32px;
}

.invoice-card-values div {
    display: flex;
    flex-direction: column;
    min-width: 125px;
}

.invoice-card-values span {
    color: var(--muted);
    font-size: 13px;
}

.invoice-card-values strong {
    margin-top: 4px;
    font-size: 18px;
}

.status-badge {
    display: inline-block;
    padding: 4px 9px;
    border-radius: 4px;
    background: #e4eef7;
    color: var(--blue-dark);
    font-size: 12px;
    font-weight: 700;
}

.primary-button,
.secondary-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 9px 17px;
    border: 1px solid var(--blue);
    border-radius: 4px;
    text-decoration: none;
    cursor: pointer;
}

.primary-button {
    color: white;
    background: var(--blue);
}

.secondary-button {
    color: var(--blue);
    background: white;
}

.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 25px;
}

.login-card {
    width: min(420px, 100%);
    padding: 38px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 8px 30px rgb(0 0 0 / 12%);
}

.login-logo {
    color: var(--blue);
    font-size: 30px;
    font-weight: 800;
    letter-spacing: 0.08em;
}

.login-card h1 {
    margin-bottom: 5px;
}

.login-card p {
    margin-top: 0;
    color: var(--muted);
}

.login-card label {
    display: block;
    margin: 18px 0 6px;
    font-weight: 700;
}

.login-card input {
    width: 100%;
    padding: 11px;
    border: 1px solid #aab1b7;
    border-radius: 4px;
}

.login-card button {
    width: 100%;
    margin-top: 24px;
}

.message-error {
    margin-top: 20px;
    padding: 12px;
    background: #ffe7e7;
    border-left: 4px solid #b90000;
}

.print-toolbar {
    width: min(210mm, calc(100% - 30px));
    margin: 24px auto 12px;
    display: flex;
    justify-content: space-between;
}

.invoice-document {
    padding-bottom: 40px;
}

.invoice-page {
    width: 210mm;
    min-height: 297mm;
    margin: 0 auto 24px;
    padding: 18mm 18mm 15mm;
    background: white;
    box-shadow: 0 5px 25px rgb(0 0 0 / 14%);
    position: relative;
    font-size: 10pt;
}

.invoice-header {
    min-height: 66px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.invoice-logo {
    color: var(--blue);
    font-size: 27px;
    font-weight: 800;
    letter-spacing: 0.04em;
}

.contact-block {
    width: 290px;
    border-top: 2px solid var(--blue);
    border-bottom: 2px solid var(--blue);
    padding: 9px 0;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.address-area {
    display: grid;
    grid-template-columns: 1fr 290px;
    gap: 55px;
    margin-top: 28px;
    min-height: 145px;
}

.recipient-address small {
    font-size: 8pt;
}

.recipient-address p {
    margin-top: 24px;
    line-height: 1.25;
}

.invoice-data h3 {
    margin: 0 0 13px;
}

.invoice-data dl,
.detail-head {
    display: grid;
    grid-template-columns: max-content 1fr;
    column-gap: 8px;
    margin: 0;
}

.invoice-data dt,
.invoice-data dd,
.detail-head dt,
.detail-head dd {
    margin: 0 0 3px;
}

.invoice-title {
    margin-top: 30px;
    color: var(--blue);
}

.invoice-title h1,
.invoice-title h2 {
    margin: 0;
    font-size: 17px;
    line-height: 1.08;
}

.invoice-meta {
    margin-top: 20px;
}

.invoice-meta p {
    margin: 0 0 9px;
}

.summary-table {
    width: 100%;
    margin-top: 20px;
    border-collapse: collapse;
}

.summary-table th {
    font-weight: normal;
    text-align: right;
    border-bottom: 1px solid var(--line);
}

.summary-table th:first-child {
    text-align: left;
}

.summary-table td {
    padding: 3px 5px;
}

.summary-table td:last-child {
    width: 120px;
    text-align: right;
}

.summary-strong td,
.summary-strong th {
    font-weight: 700;
    border-top: 1px solid var(--line);
}

.summary-final td,
.summary-final th {
    color: white;
    background: var(--blue);
    font-weight: 700;
}

.invoice-note {
    margin-top: 20px;
}

.invoice-footer {
    position: absolute;
    left: 18mm;
    right: 18mm;
    bottom: 14mm;
    padding-top: 8px;
    border-top: 1px solid #aaa;
    font-size: 8pt;
}

.detail-title {
    margin: 0 0 20px;
    color: var(--blue);
    font-size: 17px;
}

.detail-head {
    margin-bottom: 14px;
}

.detail-head dd {
    word-break: break-word;
}

.detail-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    font-size: 7.8pt;
}

.detail-table th,
.detail-table td {
    padding: 2.5px 4px;
    border-top: 1px solid #555;
    vertical-align: top;
}

.detail-table th {
    text-align: left;
    font-weight: 700;
}

.detail-table th:nth-child(1) {
    width: 28%;
}

.detail-table th:nth-child(2) {
    width: 24%;
}

.detail-table th:nth-child(3) {
    width: 11%;
    text-align: right;
}

.detail-table th:nth-child(4) {
    width: 9%;
}

.detail-table th:nth-child(5),
.detail-table th:nth-child(6) {
    width: 14%;
    text-align: right;
}

.detail-table .num {
    text-align: right;
}

.meter-table th:nth-child(1) {
    width: 23%;
}

.meter-table th:nth-child(2) {
    width: 29%;
}

.meter-table th:nth-child(3),
.meter-table th:nth-child(4),
.meter-table th:nth-child(5) {
    width: 16%;
    text-align: right;
}

.reading-note {
    margin: 4px 0 12px;
    font-size: 8pt;
}

.section-heading {
    margin: 12px 0 2px;
    font-size: 9.5pt;
}

.detail-total td {
    color: white;
    background: var(--blue);
    border-top: 0;
    font-weight: 700;
}

.detail-total td:last-child {
    text-align: right;
}

.totals-table {
    width: 100%;
    margin-top: 15px;
    border-collapse: collapse;
    font-size: 8.5pt;
}

.totals-table th,
.totals-table td {
    padding: 3px 5px;
    border-top: 1px solid #666;
}

.totals-table th {
    text-align: left;
}

.totals-table td {
    text-align: right;
}

.consumption-box {
    margin-top: 24px;
    padding-top: 8px;
    border-top: 2px solid var(--blue);
}

.consumption-box h2 {
    color: var(--blue);
    font-size: 15px;
}

@media (max-width: 900px) {
    .invoice-page {
        width: calc(100% - 20px);
        min-height: auto;
        padding: 25px;
    }

    .invoice-card,
    .invoice-card-values,
    .page-heading {
        align-items: stretch;
        flex-direction: column;
    }

    .address-area {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .contact-block {
        width: 48%;
    }
}

@media print {
    @page {
        size: A4;
        margin: 12mm;
    }

    html,
    body {
        background: white;
    }

    .no-print {
        display: none !important;
    }

    .invoice-document {
        padding: 0;
    }

    .invoice-page {
        width: auto;
        min-height: auto;
        margin: 0;
        padding: 0;
        box-shadow: none;
        break-after: page;
        page-break-after: always;
    }

    .invoice-page:last-child {
        break-after: auto;
        page-break-after: auto;
    }

    .invoice-footer {
        left: 0;
        right: 0;
        bottom: 0;
    }
}


/* Build 03 – Datenimport */

.message-shell {
    width: min(1180px, calc(100% - 40px));
    margin: 22px auto -10px;
}

.app-message {
    padding: 14px 17px;
    border-left: 5px solid;
    background: white;
    box-shadow: 0 2px 9px rgb(0 0 0 / 8%);
}

.app-message-success {
    border-color: #27833b;
}

.app-message-warning {
    border-color: #c98700;
    background: #fff9e8;
}

.app-message-error {
    border-color: #b3261e;
    background: #fff0ef;
}

.upload-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 24px;
}

.upload-card {
    padding: 26px;
    background: white;
    border-top: 5px solid var(--blue);
    border-radius: 5px;
    box-shadow: 0 3px 14px rgb(0 0 0 / 9%);
}

.upload-card-heading {
    display: flex;
    gap: 15px;
    align-items: flex-start;
}

.upload-card-heading h2 {
    margin: 1px 0 5px;
}

.upload-card-heading p {
    margin: 0;
    color: var(--muted);
}

.upload-number {
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    display: grid;
    place-items: center;
    color: white;
    background: var(--blue);
    border-radius: 50%;
    font-weight: 700;
}

.file-example {
    margin: 22px 0 15px;
    padding: 9px 11px;
    background: #f3f5f7;
    border: 1px solid #d9dde0;
    font-family: Consolas, monospace;
    font-size: 13px;
    overflow-wrap: anywhere;
}

.file-drop {
    min-height: 135px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 7px;
    border: 2px dashed #9ba8b3;
    background: #fafbfd;
    cursor: pointer;
}

.file-drop:hover {
    border-color: var(--blue);
    background: #f2f7fb;
}

.file-drop span {
    color: var(--muted);
    font-size: 13px;
}

.file-drop input {
    margin-top: 12px;
    width: 100%;
}

.upload-button {
    width: 100%;
    margin-top: 17px;
}

.import-history {
    margin-top: 32px;
    padding: 24px;
    background: white;
    box-shadow: 0 3px 14px rgb(0 0 0 / 8%);
}

.import-history h2 {
    margin-top: 0;
}

.table-scroll {
    overflow-x: auto;
}

.app-table {
    width: 100%;
    min-width: 1050px;
    border-collapse: collapse;
    font-size: 13px;
}

.app-table th,
.app-table td {
    padding: 9px 8px;
    border-bottom: 1px solid #d5dadd;
    text-align: left;
    vertical-align: top;
}

.app-table th {
    color: white;
    background: var(--blue);
    white-space: nowrap;
}

.app-table .num {
    text-align: right;
}

.import-status {
    display: inline-block;
    padding: 4px 7px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
}

.import-status-erfolgreich {
    color: #166128;
    background: #e4f4e8;
}

.import-status-warnung {
    color: #7a5200;
    background: #fff0bd;
}

.import-status-fehler {
    color: #8e1712;
    background: #ffe1df;
}

.import-status-verarbeitung {
    color: #344c61;
    background: #e5edf4;
}

.import-error-row td {
    color: #8e1712;
    background: #fff0ef;
    white-space: pre-line;
}

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


/* Build 04 – Abrechnungsperioden */

.heading-actions,
.form-actions,
.period-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.period-list {
    display: grid;
    gap: 18px;
}

.period-card {
    display: grid;
    grid-template-columns: minmax(300px, 1fr) auto auto;
    gap: 28px;
    align-items: center;
    padding: 24px;
    background: white;
    border-left: 5px solid var(--blue);
    box-shadow: 0 3px 12px rgb(0 0 0 / 8%);
}

.period-title-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.period-main h2 {
    margin: 10px 0 6px;
}

.period-main p {
    margin: 3px 0;
    color: var(--muted);
}

.period-values {
    display: flex;
    gap: 28px;
}

.period-values div {
    display: flex;
    min-width: 105px;
    flex-direction: column;
}

.period-values span {
    color: var(--muted);
    font-size: 12px;
}

.period-values strong {
    margin-top: 4px;
    font-size: 17px;
}

.period-status,
.big-status {
    display: inline-block;
    padding: 5px 9px;
    border-radius: 4px;
    font-weight: 700;
}

.period-status {
    font-size: 11px;
}

.big-status {
    margin-bottom: 18px;
}

.status-angelegt,
.status-daten_fehlen,
.status-daten-fehlen {
    color: #8e1712;
    background: #ffe1df;
}

.status-berechenbar,
.status-warning {
    color: #7a5200;
    background: #fff0bd;
}

.status-vorschau {
    color: #144b77;
    background: #dcecf8;
}

.status-fix {
    color: #166128;
    background: #e4f4e8;
}

.form-shell {
    max-width: 950px;
}

.app-form-card,
.check-card,
.issue-card,
.manual-card,
.missing-card {
    padding: 24px;
    background: white;
    box-shadow: 0 3px 14px rgb(0 0 0 / 8%);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
}

.form-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-field-wide {
    grid-column: 1 / -1;
}

.form-field label,
.manual-form label {
    font-weight: 700;
}

.form-field input,
.form-field select,
.form-field textarea,
.manual-form input {
    width: 100%;
    padding: 10px;
    border: 1px solid #aeb7bd;
    border-radius: 3px;
}

.form-actions {
    justify-content: flex-end;
    margin-top: 24px;
}

.field-error {
    color: #a51812;
    font-size: 13px;
}

.check-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 22px;
}

.check-card h2,
.issue-card h2,
.manual-card h2,
.missing-card h2 {
    margin-top: 0;
}

.check-list {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) 1fr;
    gap: 8px 18px;
    margin: 0;
}

.check-list dt {
    color: var(--muted);
}

.check-list dd {
    margin: 0;
    text-align: right;
    font-weight: 700;
}

.cost-preview {
    margin-top: 22px;
    padding: 14px;
    display: flex;
    justify-content: space-between;
    background: var(--blue);
    color: white;
}

.issue-card,
.manual-card,
.missing-card {
    margin-top: 22px;
}

.issue-error {
    border-left: 5px solid #b3261e;
}

.issue-warning {
    border-left: 5px solid #c98700;
    background: #fffaf0;
}

.manual-form {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 15px;
    align-items: end;
}

.manual-form div {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.missing-table {
    min-width: 600px;
}

.danger-zone {
    margin-top: 30px;
    padding-top: 18px;
    border-top: 1px solid #c9cdd0;
}

.danger-button {
    padding: 9px 15px;
    border: 1px solid #b3261e;
    border-radius: 4px;
    background: white;
    color: #b3261e;
    cursor: pointer;
}

.invoice-mode-banner {
    width: min(210mm, calc(100% - 30px));
    margin: 14px auto;
    padding: 13px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    font-weight: 800;
    letter-spacing: 0.04em;
}

.invoice-mode-banner.preview {
    color: #704b00;
    background: #fff0bd;
    border: 2px solid #c98700;
}

.invoice-mode-banner.fix {
    color: #155925;
    background: #e4f4e8;
    border: 2px solid #27833b;
}

.fix-form {
    display: flex;
    gap: 14px;
    align-items: center;
    letter-spacing: normal;
    font-weight: normal;
}

@media (max-width: 1000px) {
    .period-card {
        grid-template-columns: 1fr;
    }

    .period-values {
        flex-wrap: wrap;
    }
}

@media (max-width: 760px) {
    .check-grid,
    .form-grid,
    .manual-form {
        grid-template-columns: 1fr;
    }

    .page-heading,
    .heading-actions,
    .invoice-mode-banner,
    .fix-form {
        align-items: stretch;
        flex-direction: column;
    }
}
