/* Invoice sheet: A4, DIN 5008 address-window position, backgrounds instead of borders.
   The sheet is a printed document, so it does not use the website theme: it keeps Arial,
   its own scale and its own color variables (--sheet-*). Invoice color options later only
   need to override these variables on .sheet.
   Type scale: 12 px fine print (sender line, tax note, QR hint), 14 px everything else (grand total in bold),
   20 px company name and title. Spacing scale: 4, 8, 12, 16, 24, 40, 80 px. Panels and dark blocks use 14 px corners. */

@page {
    size: A4;
    margin: 0;
}

html {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.sheet {
    --sheet-accent: #0f766e;     /* table header, grand total, logo mark */
    --sheet-on-accent: #ffffff;  /* text on the accent */
    --sheet-tint: #e6f4f1;       /* panels */
    --sheet-body: #f1f8f7;       /* table body */
    --sheet-zebra: #e1eeeb;      /* every second table row */
    --sheet-ink: #14302d;        /* text */
    --sheet-muted: #4a6461;      /* labels */

    position: relative;
    display: flex;
    flex-direction: column;
    /* A4 at 96 dpi, in whole pixels (no fractional column edges). 1122 px stays below the
       printable 1122.5 px, so a single-page invoice never spills onto a blank second page. */
    width: 794px;
    min-height: 1122px;
    margin: 0 auto;
    padding: 52px 76px 40px 94px;
    background: #ffffff;
    color: var(--sheet-ink);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
    line-height: 1.45;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere; /* a very long word breaks instead of widening the layout */
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 8px 24px rgba(0, 0, 0, 0.08);
}

/* Used where the sheet is shown inside another box (home page miniature) */
.sheet--flat {
    box-shadow: none;
}

@media print {
    .sheet {
        margin: 0;
        box-shadow: none;
    }
}

/* DIN 5008 fold and punch marks */
.fold-mark {
    position: absolute;
    left: 14px;
    height: 1px;
    background: #6b7280;
}
.fold-mark--1 { top: 397px; width: 18px; }
.fold-mark--2 { top: 561px; width: 30px; }
.fold-mark--3 { top: 794px; width: 18px; }

/* Logo and one-line sender */
.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px; /* space to the sender line */
}

.brand__name {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.sender-line {
    font-size: 12px;
    color: var(--sheet-muted);
}

/* Panels */
.panel {
    padding: 16px;
    border-radius: 14px;
    background: var(--sheet-tint);
}

.sheet :where(dl, dd, p) {
    margin: 0;
}

/* Recipient (the top of the panel sits at about 157 px) and invoice details */
.parties {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 24px;
    align-items: stretch;
    margin-top: 50px;
}

.recipient {
    font-style: normal;
    line-height: 1.4;
}

.recipient strong {
    display: block;
}

.details {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.details > div {
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

.details dt {
    color: var(--sheet-muted);
}

.details dd {
    font-weight: 700;
}

.title {
    margin: 40px 0 0 16px;
    font-size: 20px;
    line-height: 1.3;
    font-weight: 700;
}

/* Items */
.items {
    margin-top: 24px;
    overflow: hidden;
    border-radius: 14px;
    background: var(--sheet-body);
}

/* Fixed column widths. The number columns are right-aligned with 16 px to the cell edge, so the
   gaps between the column titles are equal. Rows are as high as the title row. */
.items table {
    width: 100%;
    table-layout: fixed;
    border-collapse: separate;
    border-spacing: 0;
}

.items thead tr {
    background: var(--sheet-accent);
    color: var(--sheet-on-accent);
}

.items th,
.items td {
    padding: 0 16px 0 0;
    text-align: right;
}

.items th {
    padding-block: 8px;
    font-weight: 700;
    white-space: nowrap;
}

.items td {
    padding-block: var(--row-padding, 6px);
}

.items tbody tr:nth-child(even) {
    background: var(--sheet-zebra);
}

.items .pos {
    width: 60px;
    padding-right: 0;
    padding-left: 16px;
    text-align: left;
}

.items .desc {
    padding-right: 8px;
    text-align: left;
}

.items .qty {
    width: max(120px, var(--qty-width, 0px));
    white-space: nowrap;
}

.items .price {
    width: max(103px, var(--price-width, 0px));
    white-space: nowrap;
}

.items .total {
    width: max(98px, var(--total-width, 0px));
    white-space: nowrap;
}

/* Totals: same width and right edge as the details panel */
.totals {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 320px;
    margin: 24px 0 0 auto;
}

.totals__row {
    display: flex;
    justify-content: space-between;
    padding: 0 16px;
}

.totals__grand {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
    padding: 12px 16px;
    border-radius: 14px;
    background: var(--sheet-accent);
    color: var(--sheet-on-accent);
    font-size: 14px;
    font-weight: 700;
}

/* Pushes the payment panel to the bottom; the page grows when there are many items */
.spacer {
    flex-grow: 1;
    min-height: 24px;
}

/* Payment: GiroCode plus the data it encodes */
.payment {
    display: flex;
    align-items: center;
    gap: 16px;
}

.payment__qr {
    flex-shrink: 0;
    width: 96px;
    height: 96px;
}

.payment__qr svg {
    display: block;
    width: 96px;
    height: 96px;
}

.payment__body {
    flex: 1;
    min-width: 0;
}

/* Two columns of equal width: payee, IBAN, BIC | amount, reference, bank */
.payment__grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.payment__grid dl {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.payment__grid dt {
    color: var(--sheet-muted);
}

.payment__grid dd {
    font-weight: 700;
}

.payment__hint {
    margin-top: 12px;
    font-size: 12px;
    line-height: 1.45;
    color: var(--sheet-muted);
}

/* ------------------------------------------------------------------------------------------
   Create invoice page: a form to edit, and the sheet above as a read-only preview
   (assets/invoice.js fills the sheet in from the form)
   ------------------------------------------------------------------------------------------ */

/* The sheet holds every printed text in German and English; it shows one of them */
.sheet[data-lang='de'] [lang='en'],
.sheet[data-lang='en'] [lang='de'] {
    display: none;
}

/* Filled in by the script: line breaks of the typed text are kept, empty parts disappear */
.recipient[data-out],
.items .desc {
    white-space: pre-line;
}

.recipient[data-out]::first-line {
    font-weight: 700;
}

.sheet .optional:has([data-out]:empty) {
    display: none;
}

.tax-note {
    margin-top: 16px;
    font-size: 12px;
    line-height: 1.45;
}

/* On screen the sheet is as wide as the page content: it grows on large screens and shrinks on
   small ones, always in A4 proportions. When printed it is exactly A4 (see the print rules). */
.sheet-box {
    container-type: inline-size;
}

.sheet-box .sheet {
    zoom: tan(atan2(100cqw, 794px));
}

/* One tab at a time on screen; printing always prints the preview */
#editor[data-tab='edit'] [data-panel='preview'],
#editor[data-tab='preview'] [data-panel='edit'] {
    display: none;
}

/* Under 640 px the preview would be too small to read: phones only show the form. Printing still
   prints the invoice (see the print rules). */
@media screen and (max-width: 639px) {
    #editor[data-tab] [data-panel='preview'] {
        display: none;
    }

    #editor[data-tab] [data-panel='edit'] {
        display: grid;
    }
}

/* Form: cards with labelled controls. Colors and radii are the website's, not the sheet's. */
.card {
    padding: 20px;
    border-radius: var(--radius-card);
    background: #ffffff;
    box-shadow: 0 1px 3px rgb(0 0 0 / 0.08);
}

.card h2 {
    margin: 0 0 16px;
    font-size: 18px;
    font-weight: 600;
}

@media (min-width: 768px) {
    .card {
        padding: 24px;
    }
}

.control {
    display: block;
    width: 100%;
    height: 44px;
    padding: 0 12px;
    border: 0;
    border-radius: var(--radius-control);
    background: #ffffff;
    color: var(--color-ink);
    font: inherit;
    font-size: 16px; /* 16 px keeps iPhones from zooming into the field */
    outline: 1px solid rgb(20 48 45 / 0.3);
    outline-offset: -1px;
}

@media (min-width: 768px) {
    .control {
        height: 40px;
    }
}

.control::placeholder {
    color: rgb(74 100 97 / 0.65);
}

.control:hover {
    outline-color: rgb(20 48 45 / 0.6);
}

.control:focus {
    outline: 2px solid var(--color-brand);
    outline-offset: -2px;
}

textarea.control {
    height: auto;
    min-height: 44px;
    padding-block: 10px;
    resize: vertical;
    field-sizing: content;
}

@media (min-width: 768px) {
    textarea.control {
        min-height: 40px; /* as tall as the inputs next to it */
        padding-block: 8px;
    }
}

select.control {
    padding-right: 36px;
    appearance: none;
    background: #ffffff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2314302d' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 12px center;
    cursor: pointer;
}

.control--center {
    padding-inline: 4px;
    text-align: center;
}

/* Price field: the € sits where the invoice language writes it (after the number in German, before it in English) */
.control--money {
    padding-right: 32px;
    text-align: right;
}

.money__sign {
    position: absolute;
    top: 50%;
    right: 12px;
    transform: translateY(-50%);
    pointer-events: none;
}

#editor[data-lang='en'] .control--money {
    padding-right: 12px;
    padding-left: 32px;
}

#editor[data-lang='en'] .money__sign {
    right: auto;
    left: 12px;
}

/* Hints for missing details. Screen only. */
.hint {
    width: fit-content;
    margin-top: 8px;
    padding: 4px 12px;
    border-radius: var(--radius-chip);
    background: #fef3c7;
    color: #92400e;
    font-size: 14px;
    line-height: 20px;
}

@media print {
    #editor [data-panel='edit'] {
        display: none;
    }

    #editor[data-tab] [data-panel='preview'] {
        display: block;
    }

    .sheet-box .sheet {
        zoom: 1;
    }
}
