/* ============================================================
   invoice.css — Rechnungs-Editor + Druck (A4)
   Portiert & angepasst aus Alt/anti test/B2B/css/invoice.css
   ============================================================ */

:root {
  --invoice-width: 210mm;
  --invoice-min-height: 297mm;
  --font-inv-heading: 'Outfit', 'Figtree', sans-serif;
  --font-inv-body: 'Inter', 'Figtree', sans-serif;
}

/* Toolbar über der Rechnung */
.invoice-toolbar {
  max-width: var(--invoice-width);
  margin: 0 auto 18px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.invoice-toolbar-title { display: flex; flex: 1; min-width: 0; flex-direction: column; gap: 2px; }
.invoice-toolbar-title strong { font-size: 14px; }
.invoice-toolbar-title span { color: #777; font-size: 12px; }

.invoice-inventory-card {
  max-width: var(--invoice-width); margin: -6px auto 18px; padding: 14px 16px;
  box-sizing: border-box; border: 1px solid #ddd; border-radius: 12px; background: #fff;
  display: flex; align-items: center; justify-content: space-between; gap: 18px;
}
.invoice-inventory-card > div:first-child { display: flex; flex-direction: column; gap: 3px; }
.invoice-inventory-card strong { font-size: 14px; }
.invoice-inventory-card span { color: #666; font-size: 13px; }
.invoice-inventory-card.is-pending { border-color: #e6c870; background: #fffaf0; }
.invoice-inventory-card.is-applied { border-color: #a9d8b8; background: #f2fbf5; }
.invoice-inventory-card.is-neutral { background: #f7f7f5; }
.invoice-inventory-check {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: #19733a; color: #fff !important; font-size: 17px !important; font-weight: 700;
}

/* A4-Container */
.invoice-container {
  width: var(--invoice-width);
  min-height: var(--invoice-min-height);
  margin: 0 auto;
  background: #fff;
  padding: 25mm 20mm;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .12);
  box-sizing: border-box;
  font-family: var(--font-inv-body);
  font-size: 14px;
  line-height: 1.4;
  color: #000;
}

.invoice-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 2rem; }
.invoice-title { flex: 1; min-width: 0; font-size: 26px; font-weight: 500; letter-spacing: -.02em; margin-top: 10px; font-family: var(--font-inv-heading); }
.invoice-title-input { width: 100%; border: 0; border-bottom: 1px dashed #bbb; background: transparent; color: #000; font: inherit; letter-spacing: inherit; outline: none; }
.invoice-title-input:focus { border-bottom-color: #000; }
.logo-container { text-align: right; }
.logo-container img { width: 110px; max-width: 100%; height: auto; }

.sender-address { font-size: 13px; line-height: 1.5; margin-bottom: 1.5rem; }
.sender-address strong { font-weight: 600; }
.invoice-sender-input { display: block; width: min(360px, 100%); min-height: 70px; padding: 7px 9px; border: 1px dashed #bbb; border-radius: 6px; background: transparent; color: #000; font: inherit; line-height: 1.5; resize: vertical; }
.invoice-sender-input:focus { outline: none; border-style: solid; border-color: #000; }
.divider { height: 1px; background: #000; margin: 20px 0 30px; }

.invoice-container .section-title {
  font-family: var(--font-inv-heading);
  font-size: 16px; font-weight: 600;
  border-bottom: 1px solid #000; padding-bottom: 4px;
  margin: 24px 0 16px; color: #000;
}

.details-grid { display: grid; grid-template-columns: 180px 1fr; gap: 8px 0; align-items: center; }
.details-label { font-weight: 500; }
.editable-input { border: none; border-bottom: 1px dashed #ccc; font-family: inherit; font-size: inherit; width: 100%; padding: 2px 0; background: transparent; }
.editable-input:focus { outline: none; border-bottom: 1px solid #000; }

/* Tabelle */
.invoice-table { width: 100%; border-collapse: collapse; margin-top: 25px; font-size: 14px; table-layout: fixed; }
.invoice-table thead th {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
  color: #666; padding: 12px 6px; border-bottom: 2px solid #000; background: #fff;
  white-space: nowrap; vertical-align: bottom;
}
.invoice-table tbody td { padding: 12px 6px; border-bottom: 1px solid #eee; vertical-align: middle; color: #000; }

.col-pos { width: 5%; text-align: center; color: #888; }
.col-prod { width: 42%; text-align: left; }
.col-qty { width: 9%; text-align: center; }
.col-price { width: 17%; text-align: right; }
.col-total { width: 16%; text-align: right; font-weight: 600; }
.col-del { width: 78px; text-align: center; }
.invoice-table th.col-qty { text-align: center; }
.invoice-table th.col-price, .invoice-table th.col-total { text-align: right; }

.invoice-table td input {
  border: none; background: transparent; font-family: inherit; font-size: 14px;
  padding: 4px 0; width: 100%; outline: none; border-bottom: 1px solid transparent;
}
.invoice-table td input:focus { border-bottom: 1px solid #000; }
.col-qty input { text-align: center; }
.col-price input { text-align: right; }

.invoice-product-editor { display: flex; min-width: 0; flex-direction: column; align-items: stretch; gap: 4px; }
.invoice-product-picker {
  position: relative; z-index: 1;
  width: 100%; min-width: 0; padding: 7px 8px; border: 1px solid #d7d7d2; border-radius: 6px;
  background: #fff; color: transparent; font: 13px var(--font-inv-body); font-weight: 600;
}
.invoice-product-picker option { color: #111; }
.invoice-product-select-wrap { position: relative; min-width: 0; }
.invoice-product-current { position: absolute; z-index: 2; top: 50%; left: 9px; right: 34px; overflow: hidden; transform: translateY(-50%); color: #111; font-size: 13px; font-weight: 600; line-height: 1.2; text-overflow: ellipsis; white-space: nowrap; pointer-events: none; }
.invoice-line-title-input { font-weight: 600 !important; }
.invoice-catalog-print-only { display: none; font-size: 13px; }
.invoice-line-description { color: #666; font-size: 11px !important; }
.invoice-line-title { display: block; font-size: 13px; }
.invoice-line-description-print { display: block; margin-top: 2px; color: #666; font-size: 11px; line-height: 1.4; }
.invoice-row-actions { display: grid; grid-template-columns: repeat(2, 28px); justify-content: center; gap: 2px; }
.invoice-row-actions button { width: 28px; height: 24px; display: grid; place-items: center; padding: 0; border: 1px solid transparent; border-radius: 4px; background: transparent; color: #777; font: 12px var(--font-inv-body); cursor: pointer; }
.invoice-row-actions button:hover:not(:disabled) { border-color: #ddd; background: #f7f7f5; color: #111; }
.invoice-row-actions button:disabled { opacity: .25; cursor: default; }
.invoice-row-actions .del-row { font-size: 17px; color: #aaa; }
.invoice-empty-lines { padding: 24px !important; text-align: center; color: #888 !important; }
.invoice-adjustment-row td { padding-top: 7px !important; padding-bottom: 7px !important; font-size: 12px; }
.invoice-adjustment-row .plus-val { color: #1a7a3c; }
.invoice-adjustment-row .minus-val { color: #b94040; }
.invoice-tax-note { padding: 12px 0 0 8px !important; font-size: 12px; color: #444 !important; vertical-align: top; }
.invoice-tax-row td { padding-top: 7px !important; padding-bottom: 7px !important; font-size: 12px; }
.invoice-total-label { text-align: right; font-weight: bold; vertical-align: bottom !important; padding-bottom: 12px !important; font-size: 15px; }

.subtotal-row td { border: none; border-top: 1px solid #ddd !important; padding: 8px 6px 4px; }
.subtotal-label { text-align: right; font-size: 13px; color: #666; font-weight: 500; }
.subtotal-value { text-align: right; font-size: 13px; color: #666; font-weight: 600; }

.total-row td { border: none; border-top: 2px solid #000 !important; padding-top: 20px; vertical-align: top; }
.total-row .col-total { font-size: 16px; font-weight: 700; }

/* Lieferschein: 4 Spalten, keine Preise */
.lieferschein-table { table-layout: auto; }
.lieferschein-table .col-prod { width: auto; }
.lieferschein-table .col-qty, .lieferschein-table th.col-qty { width: 110px; text-align: right; }

.del-row { background: none; border: none; color: #ccc; font-size: 18px; cursor: pointer; padding: 0 6px; line-height: 1; }
.del-row:hover { color: #ff4444; }

.invoice-footer-section { margin-top: 2rem; break-inside: avoid; }
.invoice-footer-section .section-title { margin-top: 0; font-size: 14px; margin-bottom: 10px; }
.footer-info { font-size: 12px; line-height: 1.6; color: #444; }
.invoice-notes { break-inside: avoid; }
.invoice-intro { margin: 22px 0 6px; color: #333; font-size: 12px; line-height: 1.55; }
.invoice-textarea {
  display: block; width: 100%; min-height: 68px; box-sizing: border-box; resize: vertical;
  border: 1px dashed #bbb; border-radius: 6px; padding: 8px; background: transparent;
  color: #222; font: 12px/1.55 var(--font-inv-body);
}
.invoice-textarea:focus { outline: none; border-style: solid; border-color: #222; }
.invoice-textarea.payment-terms { min-height: 94px; }

/* Bearbeiten-Leiste unter der Rechnung */
.invoice-editing {
  max-width: var(--invoice-width); margin: 18px auto 0;
  background: #fff; border-radius: 12px; padding: 16px 20mm;
  box-shadow: 0 4px 16px rgba(0,0,0,.06);
}
.adj-section-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.adj-section-title { font-family: var(--font-inv-heading); font-size: 13px; font-weight: 600; color: #888; text-transform: uppercase; letter-spacing: .05em; }
.adj-buttons { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.invoice-edit-hint { max-width: 470px; margin: 5px 0 0; color: #777; font-size: 12px; line-height: 1.4; }
.btn-adj { background: #fff; border: 1px solid #ddd; padding: 6px 14px; border-radius: 6px; font-size: 13px; font-weight: 500; cursor: pointer; font-family: inherit; }
.btn-adj:hover { border-color: #000; }
.btn-adj-plus { color: #1a7a3c; border-color: #b8e6c8; background: #f2fdf5; }
.btn-adj-minus { color: #b94040; border-color: #f0c4c4; background: #fff5f5; }

.adjustments-list { display: flex; flex-direction: column; gap: 4px; }
.invoice-tax-editor { display: grid; grid-template-columns: minmax(220px, 1fr) 130px minmax(260px, 1.4fr); align-items: end; gap: 12px; margin: 14px 0; padding: 14px; border: 1px solid #e7e7e3; border-radius: 8px; background: #fafaf8; }
.invoice-tax-editor label { display: flex; min-width: 0; flex-direction: column; gap: 5px; }
.invoice-tax-editor label > span { color: #777; font-size: 10px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.invoice-tax-editor select, .invoice-tax-editor input { width: 100%; box-sizing: border-box; padding: 8px 9px; border: 1px solid #d7d7d2; border-radius: 6px; background: #fff; color: #111; font: 12px var(--font-inv-body); }
.invoice-tax-rate { position: relative; }
.invoice-tax-rate input { padding-right: 28px; text-align: right; }
.invoice-tax-rate b { position: absolute; top: 50%; right: 10px; transform: translateY(-50%); color: #777; font-size: 11px; }
.adj-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid #f0f0f0; }
.adj-badge { width: 22px; height: 22px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 15px; font-weight: 700; flex-shrink: 0; }
.adj-badge.plus { background: #e6f7ec; color: #1a7a3c; }
.adj-badge.minus { background: #fde8e8; color: #b94040; }
.adj-desc { flex: 1; border: none; border-bottom: 1px dashed #ccc; font-family: inherit; font-size: 13px; padding: 2px 4px; background: transparent; outline: none; min-width: 0; }
.adj-desc:focus { border-bottom-color: #000; }
.adj-value-group { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.adj-value { width: 80px; text-align: right; border: none; border-bottom: 1px dashed #ccc; font-family: inherit; font-size: 13px; padding: 2px 4px; background: transparent; outline: none; }
.adj-value:focus { border-bottom-color: #000; }
.adj-unit-toggle { display: flex; border: 1px solid #ddd; border-radius: 5px; overflow: hidden; }
.adj-unit-btn { background: #fff; border: none; padding: 3px 9px; font-size: 12px; font-weight: 500; cursor: pointer; color: #888; font-family: inherit; }
.adj-unit-btn.active { background: #1a1a1a; color: #fff; }
.adj-amount { width: 90px; text-align: right; font-size: 13px; font-weight: 600; flex-shrink: 0; }
.adj-amount.plus-val { color: #1a7a3c; }
.adj-amount.minus-val { color: #b94040; }

@media screen and (max-width: 900px) {
  .main.is-invoice { overflow-x: hidden; }
  .invoice-toolbar, .invoice-inventory-card, .invoice-editing { width: 100%; max-width: 100%; }
  .invoice-toolbar { align-items: flex-start; flex-wrap: wrap; }
  .invoice-toolbar-title { order: 3; flex-basis: 100%; }
  .invoice-inventory-card { align-items: flex-start; flex-direction: column; }
  .invoice-container { width: 100%; min-height: 0; padding: 28px 20px; overflow-x: auto; }
  .invoice-table { min-width: 690px; }
  .invoice-editing { padding: 16px; }
  .adj-section-header, .adj-row { align-items: stretch; flex-direction: column; }
  .adj-buttons { justify-content: flex-start; }
  .adj-row { position: relative; }
  .adj-amount { width: auto; text-align: left; }
  .adj-row > .del-row { position: absolute; top: 8px; right: 0; }
  .invoice-tax-editor { grid-template-columns: 1fr; }
}

@media screen and (max-width: 560px) {
  .invoice-toolbar .row-actions { width: 100%; display: grid; grid-template-columns: 1fr; }
  .invoice-toolbar .row-actions .btn { width: 100%; justify-content: center; }
  .invoice-header { align-items: flex-start; flex-direction: column-reverse; gap: 16px; }
  .invoice-title { width: 100%; margin-top: 0; font-size: 22px; }
  .logo-container img { width: 82px; }
  .details-grid { grid-template-columns: 1fr; gap: 4px; }
  .details-label { margin-top: 8px; font-size: 12px; }
  .invoice-container { padding: 24px 16px; overflow-x: hidden; }
  .invoice-table { min-width: 0; table-layout: auto; }
  .invoice-table thead { display: none; }
  .invoice-table tbody { display: block; }
  .invoice-line-row { display: grid; gap: 8px; margin: 0 0 12px; padding: 12px 0; border-bottom: 1px solid #ddd; }
  .invoice-line-row.is-editing { grid-template-columns: 28px repeat(3, minmax(0, 1fr)); }
  .invoice-line-row.is-readonly { grid-template-columns: 28px repeat(3, minmax(0, 1fr)); }
  .invoice-table .invoice-line-row td { padding: 0; border: 0; }
  .invoice-line-row .col-pos, .invoice-line-row .col-prod, .invoice-line-row .col-qty,
  .invoice-line-row .col-price, .invoice-line-row .col-total, .invoice-line-row .col-del { width: auto; }
  .invoice-line-row .col-pos { grid-column: 1; grid-row: 1 / 3; padding-top: 8px; }
  .invoice-line-row.is-editing .col-prod { grid-column: 2 / 5; grid-row: 1; }
  .invoice-line-row.is-readonly .col-prod { grid-column: 2 / 5; grid-row: 1; }
  .invoice-line-row .col-qty { grid-column: 2; grid-row: 2; }
  .invoice-line-row .col-price { grid-column: 3; grid-row: 2; }
  .invoice-line-row .col-total { grid-column: 4; grid-row: 2; }
  .invoice-line-row .col-del { grid-column: 2 / 5; grid-row: 3; width: auto; }
  .invoice-line-row .col-qty::before, .invoice-line-row .col-price::before, .invoice-line-row .col-total::before {
    display: block; margin-bottom: 3px; color: #888; font-size: 8px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  }
  .invoice-line-row .col-qty::before { content: 'Menge'; }
  .invoice-line-row .col-price::before { content: 'Einzelpreis'; }
  .invoice-line-row .col-total::before { content: 'Gesamt'; }
  .invoice-line-row .col-price, .invoice-line-row .col-total { text-align: left; }
  .invoice-line-row .col-price input { text-align: left; }
  .invoice-row-actions { display: flex; justify-content: flex-end; }
  .invoice-row-actions button { width: 26px; }
  .total-section { margin-top: 8px; }
  .total-section tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 5px 12px; padding: 8px 0; border-top: 1px solid #ddd; }
  .total-section tr td { padding: 0 !important; border: 0 !important; }
  .total-section tr > td:first-child { grid-column: 1 / -1; }
  .total-section tr > td:first-child:empty, .total-section tr > td.no-print { display: none; }
  .total-section .subtotal-label, .total-section .invoice-total-label, .total-section .col-price { grid-column: 1; text-align: right; }
  .total-section .subtotal-value, .total-section .col-total { grid-column: 2; text-align: right; }
  .total-section .invoice-tax-note { grid-column: 1 / -1; text-align: left; }
  .adj-buttons { display: grid; grid-template-columns: 1fr; width: 100%; }
  .adj-buttons .btn-adj { width: 100%; }
}

@media screen and (min-width: 561px) and (max-width: 820px) {
  .invoice-container { padding-inline: 14px; }
}

@media screen and (any-pointer: coarse) {
  .invoice-row-actions { grid-template-columns: repeat(2, 44px); gap: 4px; }
  .invoice-row-actions button { width: 44px; min-width: 44px; height: 44px; }
  .adj-row > .del-row { width: 44px; min-width: 44px; height: 44px; }
  .invoice-product-picker, .adj-unit-btn,
  #invoice-print input:not([type="checkbox"]):not([type="radio"]),
  #invoice-print select, #invoice-print textarea {
    min-height: 44px;
  }
}

/* ---------- Druck: nur die Rechnung ---------- */
@media print {
  html, body { background: #fff !important; }
  body * { visibility: hidden !important; }
  #invoice-print, #invoice-print *, #market-print, #market-print *, #guide-print, #guide-print * { visibility: visible !important; }
  #invoice-print, #market-print, #guide-print {
    position: absolute; left: 0; top: 0; width: 100%;
    margin: 0; padding: 18mm 16mm; box-shadow: none !important; min-height: auto;
  }
  #invoice-print input, #invoice-print .editable-input, #invoice-print textarea {
    border: none !important; background: transparent !important;
    -webkit-appearance: none; appearance: none;
  }
  #invoice-print textarea { resize: none !important; overflow: visible !important; }
  #invoice-print .invoice-catalog-print-only { display: block !important; }
  #invoice-print .invoice-table { min-width: 0; }
  #invoice-print thead { display: table-header-group; }
  #invoice-print tr, #invoice-print .invoice-notes, #invoice-print .invoice-footer-section { break-inside: avoid; }
  #invoice-print ::placeholder { color: transparent !important; }
  #market-print .market-model-group { break-inside: auto; }
  #market-print .market-check-table tr { break-inside: avoid; }
  #market-print .market-check-table input[type="checkbox"] { opacity: 1 !important; }
  #guide-print .guide-section, #guide-print .guide-mini-card, #guide-print .guide-tip { break-inside: avoid; }
  #guide-print .guide-jumps { display: none !important; }
  @page { margin: 12mm; size: A4; }
}
