/* ===== INVOICE LAYOUT ===== */
.invoice-layout {
  display: grid;
  grid-template-columns: 400px 1fr;
  gap: 28px;
  align-items: start;
  max-width: 1400px;
  height: 100%;
}

.back-btn {
  display: flex;
  align-items: center;
  color: var(--text-muted);
  margin-right: 4px;
}
.back-btn svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; }
.back-btn:hover { color: var(--text); }

/* ===== FORM PANEL ===== */
.invoice-form-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  height: 100%;
  padding-right: 4px;
}

.form-section {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.form-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

/* ===== ITEMS ===== */
.item-row {
  display: grid;
  grid-template-columns: 1fr 120px 28px;
  gap: 6px;
  margin-bottom: 6px;
  align-items: center;
}
.item-desc, .item-amount {
  padding: 8px 10px;
  border: 1px solid #C8C2BA;
  border-radius: 7px;
  font-size: 13px;
  font-family: inherit;
  background: var(--surface);
  outline: none;
  box-shadow: inset 0 1px 2px rgba(0,0,0,.04);
  transition: border-color .15s, box-shadow .15s;
}
.item-desc:focus, .item-amount:focus {
  border-color: var(--sage-deep);
  box-shadow: 0 0 0 3px rgba(95,130,120,.12), inset 0 1px 2px rgba(0,0,0,.04);
}
.item-amount { text-align: right; font-family: var(--font-mono); }
.item-remove {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
}
.item-remove:hover { background: var(--status-cancelled-bg); color: var(--status-cancelled); }
.item-remove svg { width: 13px; height: 13px; stroke: currentColor; fill: none; stroke-width: 2; }

.totals-box {
  margin-top: 14px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}
.totals-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  padding: 3px 0;
  color: var(--text-muted);
}
.totals-row.total {
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
  border-top: 1px solid var(--border);
  margin-top: 4px;
  padding-top: 6px;
}

#f_vat_rate {
  width: auto;
  margin-left: 6px;
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.payment-summary {
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: 6px;
  display: flex;
  gap: 20px;
  font-size: 13px;
  color: var(--text-muted);
}

/* ===== INVOICE SUMMARY BAR ===== */
.inv-summary {
  display: flex;
  align-items: center;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.summary-card {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 11px 20px;
  border-right: 1px solid var(--border);
}
.summary-card:first-child { padding-left: 0; }
.summary-card:last-child { border-right: none; }
.summary-label { font-size: 11px; font-weight: 500; color: var(--text-muted); white-space: nowrap; }
.summary-value { font-size: 13px; font-weight: 700; font-family: var(--font-mono); color: var(--text); white-space: nowrap; }
.summary-value.green { color: var(--status-active); }
.summary-value.orange { color: var(--status-pending); }
.summary-value.red { color: var(--status-cancelled); }

/* ===== PREVIEW PANEL ===== */
.invoice-preview-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #d4d0ca;
  border-radius: var(--radius);
  padding: 24px 20px;
  overflow-y: auto;
  height: 100%;
}

.invoice-preview-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #888;
  margin-bottom: 12px;
  align-self: flex-start;
}

/* ===== A4 DOCUMENT ===== */
.invoice-doc {
  background: white;
  width: 210mm;
  max-width: 100%;
  height: 297mm;
  display: flex;
  flex-direction: column;
  font-family: 'Jost',  sans-serif;
  font-size: 12px;
  font-weight: 350;
  color: #1a1a1a;
  box-shadow: 0 6px 32px rgba(0,0,0,.22);
  position: relative;
}

/* ===== INVOICE STAMP ===== */
.invoice-doc strong, .invoice-doc b { font-weight: 500; }
.inv-stamp {
  position: absolute;
  top: 28%;
  right: 28mm;
  transform: rotate(-18deg);
  font-family: 'Jost',  sans-serif;
  font-size: 28px;
  font-weight: 500;
  letter-spacing: 4px;
  text-transform: uppercase;
  border: 2.5px solid currentColor;
  padding: 8px 18px;
  border-radius: 6px;
  opacity: 0.82;
  pointer-events: none;
  z-index: 20;
  white-space: nowrap;
}
.inv-stamp.storniert { color: #8b0000; }
.inv-stamp.not-sent  { color: #3a3a8a; }
.inv-stamp.bezahlt   { color: #1a5c1a; }

/* Gold accent color */
:root { --gold: #C4A35A; }

/* HEADER — always top */
.inv-header {
  text-align: center;
  padding: 8mm 30mm 0;
  flex-shrink: 0;
}
.inv-logo-img {
  width: 260px;
  height: auto;
  display: block;
  margin: 0 auto;
}

/* BODY */
.inv-body {
  flex: 1;
  min-height: 0;
  padding: 0 30mm 8mm;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.inv-items-section { flex: 1; display: flex; flex-direction: column; }
.inv-bottom-section { margin-top: auto; }

/* RECHNUNG — 38px (+25%), starts 15mm from page left edge */
.inv-title {
  font-size: 38px;
  font-weight: 600;
  letter-spacing: 0.5px;
  margin-top: 14mm;
  margin-bottom: 0;
  margin-left: -15mm;
  font-family: 'Roboto',  sans-serif;
}

/* CLIENT SECTION */
.inv-client-section { margin-top: 28mm; margin-bottom: 5mm; }
.inv-client-top { margin-bottom: 7mm; }
.inv-client-project { font-weight: 500; font-size: 12px; margin-bottom: 2px; min-height: 15px; }
.inv-client-name { font-size: 12px; color: #333; min-height: 15px; }

.inv-client-addr-date {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-top: 0;
}
.inv-client-addr { font-size: 12px; color: #333; line-height: 1.5; }
.inv-date-label { font-size: 12px; white-space: nowrap; padding-bottom: 3px; }

.inv-details-grid { margin-bottom: 5mm; margin-top: 4mm; }
.inv-detail-row {
  display: grid;
  grid-template-columns: 140px 1fr;
  font-size: 12px;
  padding: 2px 0;
  line-height: 1.5;
}
.inv-detail-label { font-weight: 500; }
.inv-detail-value { color: #222; font-weight: 350; }

.inv-type-label { font-size: 12px; margin-bottom: 10px; margin-top: 10px; min-height: 16px; font-weight: 350; }

.inv-items-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 10px;
  font-size: 12px;
  table-layout: fixed;
}
.inv-items-table thead th {
  border-bottom: 1.5px solid var(--gold);
  border-top: none;
  padding: 5px 3px;
  text-align: left;
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.inv-items-table thead th:first-child { width: auto; }
.inv-items-table thead th:last-child { text-align: right; width: 135px; }
.inv-items-table tbody td {
  padding: 3px 3px;
  height: 26px;
  border-bottom: 1px solid #333;
  vertical-align: bottom;
  word-break: break-word;
  font-weight: 350;
}
.inv-items-table tbody td:last-child { text-align: right; width: 135px; }
.inv-empty-row td { color: transparent; height: 5mm !important; padding: 0 !important; border-bottom: 1px solid #ccc !important; }

.inv-totals {
  margin-left: auto;
  width: 240px;
  font-size: 12px;
  font-weight: 350;
  margin-bottom: 0;
  margin-top: 4px;
}
.inv-total-row {
  display: flex;
  justify-content: space-between;
  padding: 2.5px 0;
  border-bottom: 1px solid #333;
}
.inv-total-final {
  font-weight: 500;
  font-size: 11px;
  border-bottom: 1.5px solid var(--gold);
  padding: 3px 0;
}

/* 2 - Space between totals and Bedingungen */
.inv-bottom-section {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 6mm;
  page-break-inside: avoid;
  break-inside: avoid;
}

.inv-conditions {
  font-size: 11px;
  font-weight: 350;
  color: #555;
  line-height: 1.6;
  display: grid;
  grid-template-columns: 82px 1fr;
  gap: 4px;
  border-left: 1.5px solid var(--gold);
  padding-left: 8px;
}
.inv-conditions strong:first-child { font-size: 11px; color: #1a1a1a; font-weight: 500; }

/* Abschlussrechnung blocks */
.inv-prev-pay-block { margin-bottom: 8px; font-size: 10px; }
.inv-prev-pay-header { font-weight: 500; text-transform: uppercase; font-size: 9.5px; letter-spacing: .5px; padding: 4px 0 2px; display: flex; justify-content: space-between; }
.inv-prev-pay-row { display: flex; justify-content: space-between; padding: 2px 0; border-bottom: 1px solid #eee; font-size: 10px; }

/* FOOTER — always bottom */
.inv-footer {
  flex-shrink: 0;
  border-top: 1px solid #bbb;
  padding: 4mm 20mm 6mm;
  font-size: 10px;
  font-weight: 350;
  color: #777;
  line-height: 2;
  letter-spacing: 0.3px;
}
.inv-footer div:first-child { text-align: justify; text-align-last: justify; }
.inv-footer div:last-child { text-align: center; }
.inv-footer-label { font-weight: 500; }
.inv-footer-gf { font-weight: 500; }

/* ===== PREV PAY ROWS ===== */
.prev-pay-row {
  display: grid;
  grid-template-columns: 140px 1fr 28px;
  gap: 6px;
  margin-bottom: 6px;
  align-items: center;
}
.prev-pay-date, .prev-pay-netto,
.prev-pay-row input {
  padding: 8px 10px;
  border: 1px solid #C8C2BA;
  border-radius: 7px;
  font-size: 13px;
  font-family: inherit;
  background: var(--surface);
  outline: none;
  box-shadow: inset 0 1px 2px rgba(0,0,0,.04);
  transition: border-color .15s, box-shadow .15s;
}
.prev-pay-row input:focus {
  border-color: var(--sage-deep);
  box-shadow: 0 0 0 3px rgba(95,130,120,.12), inset 0 1px 2px rgba(0,0,0,.04);
}
.prev-pay-netto { text-align: right; font-family: var(--font-mono); }

/* Abschlussrechnung blocks — full-width grid: label | row-label | amount */
.abschluss-block,
.abschluss-remain {
  display: grid;
  grid-template-columns: 1fr 140px 90px;
  margin-top: 5px;
  padding-top: 3px;
  border-top: 1px solid #ccc;
}
.abschluss-remain { border-top: 1px solid #888; }

.abschluss-label {
  grid-column: 1;
  grid-row: 1 / 4;
  font-weight: 500;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
  color: #444;
  align-self: start;
  padding-top: 1px;
  padding-right: 8px;
}
.abschluss-remain .abschluss-label { color: #1a1a1a; }

.abschluss-row-lbl {
  text-align: right;
  padding: 2.5px 0;
  border-bottom: 1px solid #333;
  font-size: 11px;
  font-weight: 350;
}
.abschluss-row-amt {
  text-align: right;
  padding: 2.5px 0;
  border-bottom: 1px solid #333;
  font-size: 11px;
  font-weight: 350;
}
.abschluss-row-lbl.fin { border-bottom: 1.5px solid var(--gold); font-weight: 500; padding: 3px 0; }
.abschluss-row-amt.fin { border-bottom: 1.5px solid var(--gold); font-weight: 500; padding: 3px 0; }

/* Tighter gap when Abschlussrechnung */
.inv-bottom-section.abschluss { gap: 3mm; }

/* ===== PRINT ===== */
@page { size: A4; margin: 0; }

@media print {
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  body { margin: 0; padding: 0; background: white; }
  .invoice-doc { display: none !important; } /* preview hidden; print-pages take over */
}

/* ===== INVOICE STATUS BADGES ===== */
.inv-status-due { color: var(--status-pending); background: var(--status-pending-bg); }
.inv-status-paid { color: var(--status-active); background: var(--status-active-bg); }
.inv-status-partial { color: #6366f1; background: #eef2ff; }
.row-overdue-partial .inv-status-partial { color: var(--status-pending) !important; background: var(--status-pending-bg) !important; }
.inv-status-cancelled { color: var(--status-cancelled); background: var(--status-cancelled-bg); }
.inv-status-storniert { color: var(--status-cancelled); background: var(--status-cancelled-bg); font-weight: 500; letter-spacing: 0.3px; }
.inv-status-not-sent { color: #92400e; background: #fef3c7; }

/* ===== QUOTE STATUS BADGES ===== */
.quote-status-draft    { color: #6b7280; background: #f3f4f6; }
.quote-status-sent     { color: #1d4ed8; background: #eff6ff; }
.quote-status-accepted { color: var(--status-active); background: var(--status-active-bg); }
.quote-status-rejected { color: var(--status-cancelled); background: var(--status-cancelled-bg); }

/* ===== RESPONSIVE ===== */
@media (max-width: 1100px) {
  .invoice-layout { grid-template-columns: 1fr; }
  .invoice-preview-panel { display: none; }
}
