/* =========================================================
   KUNDENPORTAL – Kompatibilitäts-Layout für bestehende PHP-Seiten
   Diese Regeln greifen ausschließlich innerhalb body.portal-page.
   Dadurch bleibt die öffentliche Website unverändert.
   ========================================================= */

.portal-page .container{
    width:min(1240px,94%);
}

.portal-page .portal-main{
    padding:64px 0 88px;
}

/* Alte Klassen der vorhandenen PHP-Dateien */
.portal-page .page-head{
    display:flex;
    align-items:flex-end;
    justify-content:space-between;
    gap:28px;
    margin:0 0 32px;
    padding:34px 36px;
    background:linear-gradient(135deg,#f0f8eb 0%,#ffffff 72%);
    border:1px solid #dfead9;
    border-radius:26px;
    box-shadow:0 14px 34px rgba(22,32,43,.055);
}

.portal-page .page-head > div{
    max-width:760px;
}

.portal-page .page-head h1{
    margin:0;
    font-size:clamp(2.4rem,4.5vw,4.2rem);
    line-height:.98;
    letter-spacing:-.055em;
}

.portal-page .page-head p{
    margin:12px 0 0;
    color:var(--muted);
    font-size:1.04rem;
}

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

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

.portal-page .card{
    background:#fff;
    border:1px solid var(--line);
    border-radius:22px;
    padding:30px;
    box-shadow:0 12px 32px rgba(22,32,43,.06);
}

.portal-page .card h2{
    margin:0 0 16px;
    font-size:1.45rem;
    letter-spacing:-.025em;
}

.portal-page .card h3{
    margin-top:0;
}

.portal-page .muted{
    color:var(--muted);
}

.portal-page .metric{
    margin-top:10px;
    font-size:3rem;
    line-height:1;
    font-weight:900;
    letter-spacing:-.055em;
    color:var(--green2);
}

.portal-page .actions{
    display:flex;
    gap:10px;
    flex-wrap:wrap;
}

.portal-page .btn-secondary{
    background:#fff;
    color:var(--ink);
    border-color:#b9d8ab;
}

.portal-page .btn-secondary:hover{
    background:#f2f8ee;
    border-color:#8bc66d;
}

.portal-page .table-wrap{
    overflow:auto;
    background:#fff;
    border:1px solid var(--line);
    border-radius:18px;
}

.portal-page .table{
    width:100%;
    min-width:760px;
    border-collapse:collapse;
}

.portal-page .table th,
.portal-page .table td{
    padding:16px 18px;
    text-align:left;
    border-bottom:1px solid #edf0f2;
    vertical-align:middle;
}

.portal-page .table th{
    background:#f5f9f2;
    color:#56616a;
    font-size:.76rem;
    text-transform:uppercase;
    letter-spacing:.055em;
    font-weight:900;
}

.portal-page .table tbody tr:last-child td{
    border-bottom:0;
}

.portal-page .table tbody tr:hover td{
    background:#fbfdf9;
}

.portal-page .badge{
    display:inline-flex;
    align-items:center;
    padding:6px 10px;
    border-radius:999px;
    background:#edf8e8;
    color:#2d741b;
    font-size:.76rem;
    font-weight:900;
    white-space:nowrap;
}

.portal-page .badge-cancelled{
    background:#fff1ef;
    color:#96352b;
}

/* Admin-Dashboard: Kennzahlen deutlicher hervorheben */
.portal-page .grid > .card{
    min-height:158px;
    display:flex;
    flex-direction:column;
    justify-content:center;
    position:relative;
    overflow:hidden;
}

.portal-page .grid > .card:before{
    content:"";
    position:absolute;
    width:120px;
    height:120px;
    border-radius:50%;
    right:-42px;
    top:-42px;
    background:rgba(83,177,15,.07);
}

.portal-page .grid > .card .muted{
    font-size:.86rem;
    font-weight:800;
    text-transform:uppercase;
    letter-spacing:.045em;
}

/* Header im Portal großzügiger */
.portal-page .portal-header .nav-wrap{
    height:104px;
}

.portal-page .portal-header .brand img{
    width:230px;
    height:84px;
}

.portal-page .portal-header .nav{
    gap:30px;
}

.portal-page .portal-header .nav a{
    padding:38px 0 31px;
    font-size:.96rem;
}

.portal-page .portal-header .nav a.active:after{
    bottom:24px;
}

/* Formulare der bereits vorhandenen Seiten */
.portal-page .form-grid{
    display:grid;
    grid-template-columns:1fr 1fr;
    gap:16px;
}

.portal-page .field{
    display:flex;
    flex-direction:column;
}

.portal-page .field.full{
    grid-column:1/-1;
}

.portal-page .field label{
    display:block;
    font-size:.84rem;
    font-weight:750;
    color:#4c5761;
    margin-bottom:6px;
}

.portal-page .field input,
.portal-page .field select,
.portal-page .field textarea{
    width:100%;
    padding:13px 14px;
    border:1px solid #dce2e7;
    border-radius:10px;
    background:#fcfdfd;
    font:inherit;
    color:var(--ink);
}

.portal-page .field textarea{
    min-height:120px;
    resize:vertical;
}

.portal-page .field input:focus,
.portal-page .field select:focus,
.portal-page .field textarea:focus{
    outline:0;
    border-color:#79bc4d;
    box-shadow:0 0 0 3px rgba(83,177,15,.11);
}

/* Die Verwaltungsseiten dürfen die volle Breite nutzen */
.portal-page main .container{
    max-width:1240px;
}

/* Footer etwas vom Arbeitsbereich absetzen */
.portal-page .portal-footer{
    border-top:1px solid #26323c;
}

/* Responsiv */
@media(max-width:1020px){
    .portal-page .grid{
        grid-template-columns:1fr;
    }

    .portal-page .grid-2{
        grid-template-columns:1fr;
    }

    .portal-page .page-head{
        align-items:flex-start;
        flex-direction:column;
    }

    .portal-page .portal-header .nav-wrap{
        height:94px;
    }

    .portal-page .portal-header .nav{
        top:94px;
    }
}

@media(max-width:650px){
    .portal-page .portal-main{
        padding:38px 0 58px;
    }

    .portal-page .page-head{
        padding:26px 22px;
        border-radius:20px;
    }

    .portal-page .card{
        padding:24px;
    }

    .portal-page .form-grid{
        grid-template-columns:1fr;
    }

    .portal-page .field.full{
        grid-column:auto;
    }
}


/* =========================================================
   MOBIL: Abmelden direkt im geöffneten Portal-Menü
   ========================================================= */

.portal-mobile-logout{
    display:none;
}

@media(max-width:1020px){
    .portal-page .portal-mobile-logout{
        display:flex;
        align-items:center;
        justify-content:center;
        width:100%;
        margin-top:8px;
        padding:12px 16px;
        border-radius:10px;
        background:linear-gradient(135deg,var(--green),#3d970d);
        color:#fff!important;
        font-weight:900;
        box-shadow:0 8px 20px rgba(83,177,15,.18);
    }

    .portal-page .portal-mobile-logout:after{
        display:none!important;
    }
}


/* =========================================================
   RECHNUNGSMODUL
   ========================================================= */
.invoice-filter{display:flex;gap:8px;flex-wrap:wrap;margin:0 0 22px}
.invoice-filter-link{padding:8px 12px;border:1px solid #d7e4d0;border-radius:999px;background:#fff;font-size:.84rem;font-weight:850}
.invoice-filter-link.active,.invoice-filter-link:hover{background:#edf8e8;color:var(--green2);border-color:#9cc887}

.invoice-status{display:inline-flex;align-items:center;padding:6px 10px;border-radius:999px;font-size:.76rem;font-weight:900;white-space:nowrap}
.invoice-status-draft{background:#eef1f3;color:#53606a}
.invoice-status-open{background:#fff6df;color:#806218}
.invoice-status-paid{background:#edf8e8;color:#2d741b}
.invoice-status-cancelled{background:#fff1ef;color:#96352b}

.invoice-section-head{display:flex;justify-content:space-between;align-items:center;gap:18px;margin-bottom:16px}
.invoice-section-head h2{margin:0}
.invoice-section-head p{margin:4px 0 0}

.invoice-items{display:grid;gap:12px}
.invoice-item-row{display:grid;grid-template-columns:minmax(260px,2.5fr) .65fr .65fr 1fr 1fr 42px;gap:10px;align-items:end;padding:15px;border:1px solid #e3e8eb;border-radius:14px;background:#fbfdf9}
.invoice-remove{width:38px;height:44px;border:0;border-radius:10px;background:#fff1ef;color:#96352b;font-size:1.4rem;font-weight:900;cursor:pointer}
.invoice-live-totals{margin:24px 0 0 auto;width:min(420px,100%);display:grid;gap:9px}
.invoice-live-totals>div{display:flex;justify-content:space-between;gap:20px;padding:8px 0;border-bottom:1px solid #edf0f2}
.invoice-live-totals .grand{font-size:1.18rem;color:var(--green2);border-bottom:0;padding-top:13px}
.invoice-editor-actions{display:flex;justify-content:flex-end;gap:10px;margin-top:20px}

.invoice-paper{background:#fff;border:1px solid var(--line);border-radius:20px;padding:42px;box-shadow:0 12px 30px rgba(22,32,43,.06);max-width:1050px;margin:0 auto}
.invoice-brand-row{display:flex;justify-content:space-between;align-items:flex-start;gap:20px;border-bottom:4px solid var(--green);padding-bottom:20px}
.invoice-brand{font-size:1.75rem;font-weight:950;letter-spacing:-.04em}
.invoice-tagline{color:var(--green2);font-weight:800}
.invoice-address-grid{display:grid;grid-template-columns:1fr .8fr;gap:50px;margin:36px 0}
.invoice-smallline{font-size:.72rem;color:var(--muted);margin-bottom:24px;border-bottom:1px solid #dfe5e8;padding-bottom:5px}
.invoice-meta{display:grid;gap:8px}
.invoice-meta>div{display:flex;justify-content:space-between;gap:20px;border-bottom:1px solid #edf0f2;padding:6px 0}
.invoice-meta span{color:var(--muted)}
.invoice-paper h2{font-size:2.3rem;margin:26px 0 18px;letter-spacing:-.04em}
.invoice-lines{border:1px solid #dfe5e8;border-radius:12px;overflow:hidden}
.invoice-line{display:grid;grid-template-columns:55px minmax(240px,1fr) 130px 140px 145px;gap:12px;padding:12px 14px;border-bottom:1px solid #edf0f2;align-items:center}
.invoice-line:last-child{border-bottom:0}
.invoice-line-head{background:#f3f8ef;font-size:.76rem;text-transform:uppercase;letter-spacing:.04em;font-weight:900}
.invoice-total-box{margin:25px 0 0 auto;width:min(420px,100%);display:grid;gap:7px}
.invoice-total-box>div{display:flex;justify-content:space-between;gap:20px;padding:7px 0;border-bottom:1px solid #edf0f2}
.invoice-total-box .invoice-grand{font-size:1.25rem;color:var(--green2);border-bottom:0;padding-top:12px}
.invoice-note,.invoice-payment{margin-top:28px;padding:17px;background:#f8faf8;border:1px solid #e3e8eb;border-radius:12px}
.invoice-footer-info{display:grid;grid-template-columns:repeat(3,1fr);gap:20px;margin-top:42px;padding-top:20px;border-top:1px solid #dfe5e8;font-size:.8rem;color:#56616a}
.invoice-admin-actions{display:flex;gap:10px;flex-wrap:wrap;max-width:1050px;margin:18px auto 0}
.invoice-admin-actions form{margin:0}

@media(max-width:900px){
  .invoice-item-row{grid-template-columns:1fr 1fr}
  .invoice-description{grid-column:1/-1}
  .line-total-field{grid-column:1/-1}
  .invoice-remove{grid-column:1/-1;width:100%}
  .invoice-address-grid{grid-template-columns:1fr;gap:28px}
  .invoice-line{grid-template-columns:42px 1fr}
  .invoice-line span:nth-child(n+3){padding-left:54px}
  .invoice-footer-info{grid-template-columns:1fr}
}
@media(max-width:650px){
  .invoice-paper{padding:24px 18px;border-radius:16px}
  .invoice-brand-row{flex-direction:column}
  .invoice-item-row{grid-template-columns:1fr}
  .invoice-description,.line-total-field,.invoice-remove{grid-column:auto}
  .invoice-editor-actions{flex-direction:column}
  .invoice-editor-actions .btn{width:100%}
}

@media print{
  .site-header,.portal-footer,.no-print,.invoice-admin-actions{display:none!important}
  body.portal-page,.portal-main{background:#fff!important;padding:0!important}
  .portal-main>.container{width:100%!important;max-width:none!important}
  .invoice-paper{border:0!important;box-shadow:none!important;border-radius:0!important;max-width:none!important;padding:0!important}
}


/* =========================================================
   RECHNUNG – optimierte PDF-/Druckdarstellung auf DIN A4
   ========================================================= */

@page{
    size:A4 portrait;
    margin:13mm 12mm 14mm 12mm;
}

@media print{
    html,
    body{
        background:#fff!important;
        width:auto!important;
        min-width:0!important;
        margin:0!important;
        padding:0!important;
        font-size:10pt!important;
    }

    body.portal-page{
        background:#fff!important;
        color:#111!important;
    }

    .site-header,
    .portal-footer,
    .no-print,
    .invoice-admin-actions,
    .menu-toggle{
        display:none!important;
    }

    .portal-main{
        background:#fff!important;
        padding:0!important;
        margin:0!important;
    }

    .portal-main > .container{
        width:100%!important;
        max-width:none!important;
        margin:0!important;
        padding:0!important;
    }

    .invoice-paper{
        width:100%!important;
        max-width:none!important;
        margin:0!important;
        padding:0!important;
        border:0!important;
        border-radius:0!important;
        box-shadow:none!important;
        background:#fff!important;
        overflow:visible!important;
        font-size:9.6pt!important;
        line-height:1.35!important;
    }

    .invoice-brand-row{
        display:flex!important;
        justify-content:space-between!important;
        align-items:flex-start!important;
        gap:12mm!important;
        padding:0 0 5mm 0!important;
        margin:0 0 7mm 0!important;
        border-bottom:2px solid #53b10f!important;
        break-inside:avoid!important;
        page-break-inside:avoid!important;
    }

    .invoice-brand{
        font-size:18pt!important;
        line-height:1.05!important;
    }

    .invoice-tagline{
        font-size:9pt!important;
    }

    .invoice-status{
        font-size:8pt!important;
        padding:2mm 3mm!important;
    }

    .invoice-address-grid{
        display:grid!important;
        grid-template-columns:1fr 67mm!important;
        gap:12mm!important;
        margin:0 0 7mm 0!important;
        break-inside:avoid!important;
        page-break-inside:avoid!important;
    }

    .invoice-smallline{
        margin-bottom:6mm!important;
        padding-bottom:1.5mm!important;
        font-size:7.2pt!important;
    }

    .invoice-meta{
        display:grid!important;
        gap:1mm!important;
    }

    .invoice-meta > div{
        display:grid!important;
        grid-template-columns:1fr auto!important;
        gap:4mm!important;
        padding:1.2mm 0!important;
        font-size:8.8pt!important;
    }

    .invoice-paper h2{
        margin:0 0 4mm 0!important;
        font-size:18pt!important;
        line-height:1.1!important;
    }

    .invoice-lines{
        display:block!important;
        width:100%!important;
        overflow:visible!important;
        border:1px solid #cfd6da!important;
        border-radius:0!important;
    }

    .invoice-line{
        display:grid!important;
        grid-template-columns:10mm minmax(0,1fr) 26mm 31mm 32mm!important;
        gap:2.5mm!important;
        align-items:start!important;
        padding:2.5mm 3mm!important;
        border-bottom:1px solid #dfe4e7!important;
        font-size:8.5pt!important;
        line-height:1.3!important;
        break-inside:avoid!important;
        page-break-inside:avoid!important;
    }

    .invoice-line:last-child{
        border-bottom:0!important;
    }

    .invoice-line-head{
        display:grid!important;
        grid-template-columns:10mm minmax(0,1fr) 26mm 31mm 32mm!important;
        background:#f0f5ed!important;
        color:#111!important;
        font-size:7.2pt!important;
        font-weight:800!important;
        text-transform:uppercase!important;
        letter-spacing:.02em!important;
    }

    .invoice-line span{
        padding:0!important;
        margin:0!important;
        min-width:0!important;
        overflow-wrap:anywhere!important;
    }

    .invoice-line span:nth-child(3),
    .invoice-line span:nth-child(4),
    .invoice-line span:nth-child(5),
    .invoice-line-head span:nth-child(3),
    .invoice-line-head span:nth-child(4),
    .invoice-line-head span:nth-child(5){
        text-align:right!important;
    }

    .invoice-total-box{
        width:78mm!important;
        margin:6mm 0 0 auto!important;
        break-inside:avoid!important;
        page-break-inside:avoid!important;
    }

    .invoice-total-box > div{
        display:grid!important;
        grid-template-columns:1fr auto!important;
        gap:8mm!important;
        padding:1.6mm 0!important;
        font-size:9pt!important;
    }

    .invoice-total-box .invoice-grand{
        font-size:11pt!important;
        padding-top:2.5mm!important;
    }

    .invoice-note,
    .invoice-payment{
        margin-top:6mm!important;
        padding:3mm 4mm!important;
        border:1px solid #dfe4e7!important;
        border-radius:0!important;
        background:#fff!important;
        font-size:8.8pt!important;
        break-inside:avoid!important;
        page-break-inside:avoid!important;
    }

    .invoice-footer-info{
        display:grid!important;
        grid-template-columns:1fr 1fr 1fr!important;
        gap:6mm!important;
        margin-top:8mm!important;
        padding-top:4mm!important;
        border-top:1px solid #cfd6da!important;
        font-size:7.6pt!important;
        line-height:1.35!important;
        break-inside:avoid!important;
        page-break-inside:avoid!important;
    }

    /* Verhindert, dass durch die mobilen Regeln die Rechnung im PDF
       plötzlich in eine 1- oder 2-spaltige Darstellung fällt. */
    .invoice-description,
    .line-total-field,
    .invoice-remove{
        grid-column:auto!important;
    }

    a{
        color:inherit!important;
        text-decoration:none!important;
    }

    *{
        -webkit-print-color-adjust:exact!important;
        print-color-adjust:exact!important;
    }
}


/* Rechnungslogo */
.invoice-logo-wrap{
    display:flex;
    align-items:flex-start;
}
.invoice-logo{
    display:block;
    width:150px;
    max-width:42vw;
    height:auto;
}
.invoice-delete-permanent{
    font-weight:900;
}

@media print{
    .invoice-logo{
        width:42mm!important;
        max-width:42mm!important;
        height:auto!important;
    }
    .invoice-logo-wrap{
        display:block!important;
    }
}
