/* ============================================================
   Angebots-Generator – Werbe-Service Kühnau
   ============================================================ */

:root {
    --c-bg: #eef2f8;
    --c-bg-grad-1: #e8eef9;
    --c-bg-grad-2: #eef2f8;
    --c-panel: #ffffff;
    --c-border: #dde3ec;
    --c-border-strong: #c8d1de;
    --c-text: #1c2531;
    --c-muted: #69737f;
    --c-primary: #2563eb;
    --c-primary-dark: #1d4ed8;
    --c-accent: #f6c700;

    --radius: 14px;
    --radius-sm: 9px;
    --shadow-sm: 0 1px 2px rgba(16, 27, 45, .06), 0 2px 6px rgba(16, 27, 45, .05);
    --shadow-md: 0 6px 20px rgba(16, 27, 45, .10);
    --shadow-lg: 0 18px 50px rgba(16, 27, 45, .18);
    --ring: 0 0 0 3px rgba(37, 99, 235, .18);

    /* Maße A4 */
    --a4-w: 210mm;
    --a4-h: 297mm;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: "Inter", "Segoe UI", Arial, sans-serif;
    color: var(--c-text);
    background: linear-gradient(160deg, var(--c-bg-grad-1), var(--c-bg-grad-2) 60%);
    background-attachment: fixed;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* ---------- App-Kopf ---------- */
.app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    background: linear-gradient(120deg, #0d1726 0%, #14233b 60%, #1b2c49 100%);
    color: #fff;
    box-shadow: 0 2px 14px rgba(0, 0, 0, .22);
    border-bottom: 1px solid rgba(255, 255, 255, .06);
}
.app-header__inner {
    max-width: 1500px;
    margin: 0 auto;
    padding: 14px 22px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}
.app-header h1 {
    font-size: 19px;
    margin: 0;
    font-weight: 700;
    letter-spacing: .2px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.app-header h1::before {
    content: "";
    width: 10px;
    height: 22px;
    border-radius: 3px;
    background: linear-gradient(var(--c-accent), #e0a800);
    box-shadow: 0 0 12px rgba(246, 199, 0, .5);
}
.app-header__actions { display: flex; gap: 10px; flex-wrap: wrap; }

.btn {
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    border: none;
    border-radius: 10px;
    padding: 10px 18px;
    cursor: pointer;
    transition: background .15s, transform .08s, box-shadow .15s;
    white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn--primary {
    background: linear-gradient(180deg, #2f6df0, var(--c-primary));
    color: #fff;
    box-shadow: 0 4px 14px rgba(37, 99, 235, .35);
}
.btn--primary:hover { background: linear-gradient(180deg, #2563eb, var(--c-primary-dark)); box-shadow: 0 6px 18px rgba(37, 99, 235, .45); }
.btn--ghost { background: rgba(255, 255, 255, .04); color: #cdd5e0; border: 1px solid #38465c; }
.btn--ghost:hover { background: rgba(255, 255, 255, .12); color: #fff; }
.btn--add {
    background: #eef4ff;
    color: var(--c-primary-dark);
    width: 100%;
    margin-top: 6px;
    border: 1px dashed #aac3f5;
}
.btn--add:hover { background: #dde9ff; }

/* ---------- Layout ---------- */
.layout {
    display: grid;
    grid-template-columns: 440px 1fr;
    gap: 28px;
    max-width: 1500px;
    margin: 0 auto;
    padding: 28px 22px 64px;
    align-items: start;
}

/* ---------- Formular-Panel ---------- */
.panel {
    position: sticky;
    top: 84px;
    background: var(--c-panel);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: 20px;
    max-height: calc(100vh - 108px);
    overflow-y: auto;
    box-shadow: var(--shadow-md);
    scrollbar-width: thin;
    scrollbar-color: var(--c-border-strong) transparent;
}
.panel::-webkit-scrollbar { width: 9px; }
.panel::-webkit-scrollbar-thumb { background: var(--c-border-strong); border-radius: 8px; border: 2px solid var(--c-panel); }
.form-group {
    border: 1px solid var(--c-border);
    border-radius: 12px;
    padding: 16px 16px 18px;
    margin: 0 0 18px;
    background: #fcfdff;
}
.form-group legend {
    font-weight: 700;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .8px;
    color: var(--c-primary-dark);
    padding: 2px 10px;
    background: #eef4ff;
    border-radius: 999px;
}
.panel label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--c-muted);
    margin-bottom: 12px;
}
.panel label:last-child { margin-bottom: 0; }
.panel input,
.panel select {
    display: block;
    width: 100%;
    margin-top: 6px;
    padding: 10px 12px;
    font: inherit;
    font-size: 14px;
    color: var(--c-text);
    border: 1px solid var(--c-border-strong);
    border-radius: var(--radius-sm);
    background: #fbfcfe;
    transition: border-color .15s, box-shadow .15s, background .15s;
}
.panel select {
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2369737f' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 38px;
}
.panel input:hover,
.panel select:hover { border-color: #aab6c6; }
.panel input:focus,
.panel select:focus {
    outline: none;
    border-color: var(--c-primary);
    box-shadow: var(--ring);
    background: #fff;
}
.form-row { display: flex; gap: 12px; }
.form-row label { flex: 1; }

/* Positions-Zeilen im Formular */
.item-card {
    border: 1px solid var(--c-border);
    border-radius: 12px;
    padding: 14px;
    margin-bottom: 12px;
    background: linear-gradient(180deg, #f9fbfe, #f3f7fc);
    position: relative;
    box-shadow: var(--shadow-sm);
}
.item-card__head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}
.item-card__title { font-size: 12px; font-weight: 700; color: var(--c-muted); text-transform: uppercase; letter-spacing: .5px; }
.item-card .form-row { margin-bottom: 8px; }
.item-card label { margin-bottom: 8px; }
.item-remove {
    background: #fee2e2;
    color: #b91c1c;
    border: none;
    border-radius: 8px;
    width: 28px;
    height: 28px;
    font-size: 17px;
    line-height: 1;
    cursor: pointer;
    transition: background .15s, transform .08s;
}
.item-remove:hover { background: #fecaca; transform: scale(1.05); }

/* ============================================================
   ANGEBOTSBLATT (A4) – echtes Briefpapier als Hintergrundbild
   ============================================================ */
.preview {
    display: flex;
    justify-content: center;
    align-items: flex-start;
}
/* Wrapper, der das fixe A4-Blatt flüssig auf die Bildschirmbreite skaliert.
   Die Wrapper-Größe entspricht dem skalierten Blatt, damit kein Leerraum
   oder Überlauf entsteht. */
.sheet-scale {
    width: calc(794px * var(--sheet-scale, 1));
    height: calc(1123px * var(--sheet-scale, 1));
    flex: 0 0 auto;
}
.sheet {
    width: var(--a4-w);
    height: var(--a4-h);
    background: #fff url("../images/briefpapier-print.jpg") top center / 100% 100% no-repeat;
    box-shadow: var(--shadow-lg);
    border-radius: 4px;
    position: relative;
    color: #1a1a1a;
    font-size: 9.2pt;
    line-height: 1.35;
    transform: scale(var(--sheet-scale, 1));
    transform-origin: top left;
}

/* Dynamischer Inhalt liegt über dem Briefpapier im weißen Bereich.
   Werte in mm sind auf das Briefpapier-Layout abgestimmt. */
.sheet__content {
    position: absolute;
    top: 62mm;
    left: 22mm;
    right: 14mm;
    bottom: 52mm;
}

/* Kundenadresse */
.cust-address {
    font-style: normal;
    display: flex;
    flex-direction: column;
    gap: .4mm;
    font-size: 10pt;
    min-height: 24mm;
}
.cust-address__city { margin-top: 3mm; }

/* Titel */
.doc-title {
    text-align: right;
    font-size: 26pt;
    font-weight: 800;
    margin: 4mm 0 8mm;
    color: #111;
}

/* Meta */
.meta {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 4mm;
    font-size: 9pt;
}
.meta__left div { display: flex; gap: 4mm; margin-bottom: 1mm; }
.meta__label { color: #333; }
.meta__left .meta__label { width: 28mm; display: inline-block; }
.meta__value { font-weight: 700; }
.meta__right { display: flex; gap: 6mm; padding-right: 4mm; }

/* Positionstabelle */
.items-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 8.6pt;
}
.items-table thead th {
    text-align: left;
    border-top: .6pt solid #111;
    border-bottom: .6pt solid #111;
    padding: 1.4mm 1.5mm;
    font-weight: 700;
}
.items-table tbody td {
    padding: 1.4mm 1.5mm;
    vertical-align: top;
}
.col-anz, .col-mwst, .col-netto, .col-abzug, .col-gesamt { text-align: right; }
.items-table th.col-anz,
.items-table th.col-mwst,
.items-table th.col-netto,
.items-table th.col-abzug,
.items-table th.col-gesamt { text-align: right; }
.col-pos { width: 9mm; }
.col-anz { width: 11mm; }
.col-einheit { width: 14mm; }
.col-artnr { width: 16mm; }
.col-mwst { width: 14mm; }
.col-netto { width: 17mm; }
.col-abzug { width: 15mm; }
.col-gesamt { width: 18mm; }

/* Summen */
.totals {
    margin-top: 3mm;
    margin-left: auto;
    width: 70mm;
    font-size: 9pt;
}
.totals__row {
    display: flex;
    justify-content: space-between;
    padding: .6mm 0;
}
.totals__row span:first-child { color: #222; }
.totals__row span:last-child { font-variant-numeric: tabular-nums; }
.totals__row--strong {
    font-weight: 800;
    border-top: .4pt solid #111;
    margin-top: 1mm;
    padding-top: 1mm;
}

/* ============================================================
   DRUCK
   ============================================================ */
@media print {
    @page { size: 210mm 297mm; margin: 0; }

    html, body {
        background: #fff;
        width: 210mm;
        height: 297mm;
        margin: 0 !important;
        padding: 0 !important;
        overflow: hidden;
    }
    .no-print { display: none !important; }
    .layout {
        display: block;
        max-width: none;
        margin: 0 !important;
        padding: 0 !important;
    }
    .preview {
        display: block;
        margin: 0 !important;
        padding: 0 !important;
    }
    .sheet {
        position: absolute;
        top: 0;
        left: 0;
        width: 210mm;
        height: 297mm;
        box-shadow: none;
        border-radius: 0;
        margin: 0 !important;
        overflow: hidden;
        page-break-after: avoid;
        page-break-inside: avoid;
        transform: none;
    }
    .sheet-scale { width: auto; height: auto; }
    /* Farben/Hintergründe im Druck erzwingen */
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
}

/* ============================================================
   RESPONSIVE – Tablet & Handy
   ============================================================ */

/* Ab hier einspaltig: Formular oben, Vorschau darunter.
   Das A4-Blatt wird flüssig auf die verfügbare Breite skaliert. */
@media (max-width: 1300px) {
    .layout {
        grid-template-columns: 1fr;
        gap: 22px;
        padding: 22px 18px 56px;
    }
    .panel {
        position: static;
        max-height: none;
    }
    :root { --sheet-scale: min(1, calc((100vw - 36px) / 794)); }
}

/* Tablet */
@media (max-width: 820px) {
    .app-header__inner { padding: 12px 16px; }
    .app-header h1 { font-size: 17px; }
    .layout { padding: 18px 14px 48px; gap: 18px; }
    .panel { padding: 16px; border-radius: 12px; }
    :root { --sheet-scale: min(1, calc((100vw - 28px) / 794)); }
}

/* Handy */
@media (max-width: 560px) {
    .app-header__inner {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    .app-header h1 { justify-content: center; font-size: 16px; }
    .app-header__actions { justify-content: stretch; }
    .app-header__actions .btn { flex: 1; text-align: center; }
    .layout { padding: 14px 10px 40px; gap: 14px; }
    .panel { padding: 13px; }
    .form-group { padding: 13px 12px 14px; }
    /* Eng nebeneinander stehende Felder untereinander stapeln */
    .form-row { flex-direction: column; gap: 0; }
    .form-row label { margin-bottom: 12px; }
    .form-row label:last-child { margin-bottom: 0; }
    :root { --sheet-scale: min(1, calc((100vw - 20px) / 794)); }
}

