/**
 * ELMETIC ServiceHub — Gemeinsame Dokumentenfamilien-CSS
 * Namespace: doc-* (document engine)
 *
 * Gilt für ALLE Firmendokumente:
 *   Angebot | Auftragsbestätigung | Lieferschein | Rechnung |
 *   Gutschrift | Mahnung | Bestellung
 *
 * Designprinzipien:
 * - ruhig, hochwertig, professionell
 * - einheitliche Ästhetik über alle Typen
 * - A4-Format sauber darstellbar
 * - Footer-Safe-Area niemals überdruckt
 * - Mehrseitig mit Übertrag sauber
 */

/* ============================================================
   RESET / BASE
   ============================================================ */
.doc-body {
  margin: 0;
  padding: 0;
  background: #f0f0f0;
  font-family: 'Helvetica Neue', Arial, sans-serif;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.doc-shell {
  display: flex;
  flex-direction: column;
  gap: 32px;
  padding: 32px;
  max-width: 900px;
  margin: 0 auto;
}

/* ============================================================
   SEITE
   ============================================================ */
.doc-page {
  position: relative;
  background: #ffffff;
  border-radius: 6px;
  box-shadow: 0 2px 20px rgba(0, 0, 0, 0.12);
  width: 210mm;
  min-height: 297mm;
  height: 297mm;
  padding: 0;
  box-sizing: border-box;
  overflow: hidden;
  page-break-inside: avoid;
  break-inside: avoid-page;
}

.doc-page__content {
  position: relative;
  z-index: 1;
  padding: 25px 36px 220px 36px;
  min-height: 297mm;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
}

/* Spacer: drückt Übertrag / Summen / Closing ans Seitenende */
.doc-page-spacer {
  flex: 1 0 0px;
}

/* ============================================================
   KOPF: Absender + Logo
   ============================================================ */
.doc-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding-bottom: 16px;
  border-bottom: 1px solid #e4e4e4;
  margin-bottom: 8px;
  page-break-inside: avoid;
  break-inside: avoid;
}

.doc-head--follow {
  padding-bottom: 12px;
  margin-bottom: 20px;
}

.doc-head__sender {
  font-size: 9pt;
  line-height: 1.65;
  color: #1a1a1a;
}

.doc-head__company {
  font-weight: 700;
  font-size: 10pt;
  letter-spacing: 0.02em;
  color: #111;
}

.doc-head__line {
  color: #444;
}

.doc-head__logo {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 130px;
  min-height: 56px;
  flex-shrink: 0;
}

.doc-logo__img {
  max-width: 140px;
  max-height: 60px;
  object-fit: contain;
}

.doc-logo__text {
  font-size: 22pt;
  font-weight: 900;
  letter-spacing: 0.06em;
  color: #1a1a1a;
}

.doc-head__follow-label {
  font-size: 10pt;
  color: #888;
  font-style: italic;
  align-self: center;
}

/* ============================================================
   ABSENDER-LINIE (Klapptext über Empfänger)
   ============================================================ */
.doc-sender-line {
  font-size: 8.5pt;
  color: #888;
  border-bottom: 1px solid #e4e4e4;
  padding-bottom: 6px;
  margin-bottom: 20px;
  letter-spacing: 0.01em;
  page-break-inside: avoid;
  break-inside: avoid;
}

/* ============================================================
   EMPFÄNGER + META-BLOCK
   ============================================================ */
.doc-address-meta {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  margin-bottom: 28px;
  page-break-inside: avoid;
  break-inside: avoid;
}

.doc-recipient {
  flex: 1;
  min-width: 0;
}

.doc-recipient__name {
  font-size: 13pt;
  font-weight: 600;
  color: #111;
  line-height: 1.3;
  margin-bottom: 6px;
}

.doc-recipient > div:not(.doc-recipient__name) {
  font-size: 9.5pt;
  line-height: 1.7;
  color: #333;
}

.doc-meta {
  min-width: 260px;
  flex-shrink: 0;
}

.doc-meta__row {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 6px;
  font-size: 9pt;
  line-height: 1.7;
  align-items: baseline;
}

.doc-meta__label {
  font-weight: 600;
  color: #333;
}

.doc-meta__value {
  text-align: right;
  color: #111;
}

/* ============================================================
   VORTEXT
   ============================================================ */
.doc-intro {
  font-size: 9.5pt;
  line-height: 1.75;
  color: #333;
  max-width: 740px;
  margin-bottom: 24px;
  white-space: pre-wrap;
  page-break-inside: avoid;
  break-inside: avoid;
}

/* ============================================================
   DOKUMENTTITEL
   ============================================================ */
.doc-title {
  display: flex;
  align-items: baseline;
  gap: 16px;
  padding-left: 14px;
  margin-bottom: 24px;
  page-break-inside: avoid;
  break-inside: avoid;
}

.doc-title__text {
  font-size: 16pt;
  font-weight: 700;
  letter-spacing: 0.015em;
  color: #111;
  line-height: 1.2;
}

.doc-title__sub {
  font-size: 10pt;
  color: #555;
  font-weight: 400;
}

/* ============================================================
   TABELLE
   ============================================================ */
.doc-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 9pt;
  margin-bottom: 0;
  page-break-inside: auto;
  break-inside: auto;
}

.doc-table thead {
  display: table-header-group;
}

.doc-table tr,
.doc-table th,
.doc-table td {
  page-break-inside: avoid;
  break-inside: avoid;
}

.doc-th {
  font-size: 8pt;
  font-weight: 700;
  color: #555;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 7px 8px;
  border-bottom: 2px solid #1a1a1a;
  text-align: left;
  white-space: nowrap;
}

.doc-th--pos {
  text-align: center;
  width: 6%;
}

.doc-th--qty,
.doc-th--price,
.doc-th--discount,
.doc-th--total {
  text-align: right;
}

.doc-td--pos {
  text-align: center;
  color: #888;
  font-size: 9pt;
  white-space: nowrap;
}

.doc-td {
  padding: 7px 8px;
  border-bottom: 1px solid #e8e8e8;
  vertical-align: top;
  color: #222;
  line-height: 1.45;
}

.doc-td--unit {
  color: #555;
  font-size: 9.5pt;
}

.doc-td--qty,
.doc-td--price,
.doc-td--discount,
.doc-td--total {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.doc-td--discount {
  color: #888;
}

.doc-td--empty {
  color: #999;
  font-style: italic;
  padding: 16px 8px;
}

.doc-tr:last-child .doc-td {
  border-bottom: 2px solid #1a1a1a;
}

/* ============================================================
   ÜBERTRAG (Carry-Forward / Carry-Over)
   ============================================================ */
.doc-carry {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 20px;
  padding: 6px 0;
  font-size: 9pt;
  font-weight: 600;
  color: #444;
  border-top: 1px solid #ccc;
  border-bottom: 1px solid #ccc;
  margin: 8px 0;
  page-break-inside: avoid;
  break-inside: avoid;
}

.doc-carry__label {
  color: #555;
  font-weight: 500;
}

.doc-carry__amount {
  min-width: 120px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ============================================================
   SUMMENBLOCK
   ============================================================ */
.doc-totals {
  margin-top: 16px;
  margin-left: auto;
  width: 280px;
  border: 1px solid #ddd;
  border-radius: 3px;
  background: #fafafa;
  padding: 12px 16px;
  page-break-inside: avoid;
  break-inside: avoid;
}

.doc-totals__row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 4px 0;
  font-size: 9pt;
  border-bottom: 1px solid #eee;
  color: #333;
}

.doc-totals__row:last-child {
  border-bottom: none;
}

.doc-totals__row--discount {
  color: #333;
  font-size: 9pt;
}

.doc-totals__row--tax {
  color: #666;
}

.doc-totals__row--gross {
  font-size: 10.5pt;
  font-weight: 800;
  color: #111;
  padding-top: 10px;
  border-top: 2px solid #1a1a1a;
  border-bottom: none;
  margin-top: 4px;
}

.doc-totals__label {
  font-weight: 500;
}

.doc-totals__value {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* ============================================================
   ABSCHLUSSBEREICH
   ============================================================ */
.doc-payment-terms {
  margin-top: 16px;
  font-size: 9pt;
  line-height: 1.7;
  color: #333;
  max-width: 740px;
  page-break-inside: avoid;
  break-inside: avoid;
}

.doc-payment-terms__label {
  font-weight: 700;
  margin-right: 4px;
}

.doc-closing {
  margin-top: 12px;
  font-size: 9pt;
  line-height: 1.65;
  color: #444;
  max-width: 740px;
  white-space: pre-wrap;
  page-break-inside: avoid;
  break-inside: avoid;
}

.doc-action-link {
  margin-top: 24px;
  padding: 14px 18px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #f9fafb;
  max-width: 500px;
  page-break-inside: avoid;
  break-inside: avoid;
}

.doc-action-link__title {
  font-weight: 700;
  font-size: 11pt;
  margin-bottom: 4px;
}

.doc-action-link__desc {
  font-size: 10pt;
  color: #6b7280;
  margin-bottom: 6px;
}

.doc-action-link__url {
  font-size: 10pt;
  color: #111;
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-all;
}

/* ============================================================
   UNTERSCHRIFTSBEREICH (Lieferschein)
   ============================================================ */
.doc-signature {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 48px;
  margin-top: 48px;
  max-width: 600px;
  page-break-inside: avoid;
  break-inside: avoid;
}

.doc-signature__line {
  height: 1px;
  background: #333;
  margin-bottom: 8px;
}

.doc-signature__label {
  font-size: 9.5pt;
  color: #666;
}

/* ============================================================
   FOOTER — immer frei, niemals überdruckt
   ============================================================ */
.doc-footer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  min-height: 118px;
  padding: 10px 44px 18px 44px;
  border-top: 1px solid #e4e4e4;
  background: #ffffff;
  page-break-inside: avoid;
  break-inside: avoid;
}

.doc-footer::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 10px;
  background: #e73d25;
  pointer-events: none;
}

.doc-footer__cols {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  font-size: 8.5pt;
  line-height: 1.6;
  color: #666;
}

.doc-footer__col {
  flex: 1;
  white-space: pre-line;
}

.doc-footer__col--center {
  text-align: center;
}

.doc-footer__col--right {
  text-align: right;
}

.doc-footer__paging {
  text-align: right;
  font-size: 8pt;
  color: #aaa;
  margin-top: 6px;
}

/* ============================================================
   DRUCK / @media print
   ============================================================ */
@media print {
  .doc-body {
    background: transparent;
  }

  .doc-shell {
    padding: 0;
    gap: 0;
    max-width: none;
  }

  .doc-page {
    border-radius: 0;
    box-shadow: none;
    page-break-after: always;
    width: 210mm;
    min-height: 297mm;
    height: 297mm;
    margin: 0;
  }

  .doc-page:last-child {
    page-break-after: avoid;
  }

  .doc-footer {
    position: absolute;
  }
}

/* ============================================================
   BRIEFPAPIER / LETTERHEAD
   ============================================================ */
.doc-letterhead-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  min-height: 100%;
  background-size: cover;
  background-position: center top;
  background-repeat: no-repeat;
  pointer-events: none;
  z-index: 0;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

/* ============================================================
   FALZMARKE (DIN 5008) für Fensterkuvert
   ============================================================ */
.doc-page::before {
  content: '';
  position: absolute;
  left: 0;
  top: 105mm;
  width: 6mm;
  height: 0;
  border-top: 0.5pt solid #888;
  z-index: 3;
  pointer-events: none;
}

.doc-page--letterhead {
  padding-top: 0;
}

.doc-page--letterhead .doc-page__content {
  padding-top: 50mm; /* Platz für Briefpapier-Kopf (Fenster ab 50mm) */
  padding-bottom: 340px; /* Mehr Platz für dekorative Briefpapier-Fußzeile */
}

/* Adressfeld für Fensterkuvert: rechts ausrichten, Fensterbreite begrenzen */
.doc-page--letterhead .doc-sender-line {
  margin-left: 9mm;
  margin-bottom: 8px;
  max-width: 80mm;
  border-bottom: none;
}

.doc-page--letterhead .doc-recipient {
  margin-left: 9mm;
  max-width: 80mm;
}

/* Mindesthöhe: Begrüßungstext unter das Adressfenster drücken (Fenster endet bei ~90mm) */
.doc-page--letterhead .doc-address-meta {
  min-height: 35mm;
}

.doc-page--letterhead > *:not(.doc-letterhead-bg) {
  position: relative;
  z-index: 1;
}

.doc-page--letterhead .doc-footer {
  z-index: 1;
}

@media print {
  .doc-letterhead-bg {
    position: fixed;
    left: 0;
    top: 0;
    width: 210mm;
    height: 297mm;
  }
}

/* ============================================================
   POSITIONSTYPEN (Gruppe, Optional, Pauschal)
   ============================================================ */
.doc-tr--group {
  background: #f5f5f5;
}

.doc-tr--group .doc-td--group-header {
  padding: 10px 8px 6px;
  font-size: 10pt;
  font-weight: 700;
  color: #1a1a1a;
  border-bottom: 1.5px solid #ccc;
  border-top: none;
}

.doc-tr--optional .doc-td {
  color: #888;
  font-style: italic;
}

.doc-tr--pauschale .doc-td--desc {
  font-weight: 600;
}

.doc-type-label {
  font-size: 7.5pt;
  font-weight: 400;
  font-style: italic;
  margin-left: 6px;
  vertical-align: baseline;
  white-space: nowrap;
}

.doc-type-label--optional {
  color: #999;
}

/* ============================================================
   ÜBERTRAG-RICHTUNG (carry-in / carry-out)
   ============================================================ */
.doc-carry--in {
  border-top: none;
  border-bottom: 1px dashed #bbb;
  margin-top: 0;
  margin-bottom: 8px;
  background: #fafafa;
  padding: 8px 12px;
  border-radius: 2px;
}

.doc-carry--out {
  border-bottom: none;
  border-top: 1px dashed #bbb;
  margin-top: 8px;
  margin-bottom: 0;
  background: #fafafa;
  padding: 8px 12px;
  border-radius: 2px;
}

/* ============================================================
   ANGEBOTSANNAHME-SEITE (Acceptance Page)
   ============================================================ */

/* Content-Bereich als Flex-Column damit der CTA-Button unten bleibt */
.doc-page__content--acceptance {
  display: flex;
  flex-direction: column;
}

.doc-acceptance {
  flex: 1;
  display: flex;
  flex-direction: column;
  margin-top: 8px;
}

/* Spacer drückt CTA an den unteren Rand */
.doc-acceptance__spacer {
  flex: 1;
  min-height: 24px;
}

/* ── Titel ── */
.doc-acceptance__title {
  font-size: 19.5pt;
  font-weight: 700;
  letter-spacing: 0.015em;
  color: #111;
  line-height: 1.2;
  padding-left: 14px;
  margin-bottom: 24px;
}

/* ── Referenzbox ── */
.doc-acceptance__ref {
  margin-bottom: 28px;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  overflow: hidden;
}

.doc-acceptance__ref-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 18px;
  font-size: 10.5pt;
  line-height: 1.5;
  border-bottom: 1px solid #ebebeb;
}

.doc-acceptance__ref-row:last-child {
  border-bottom: none;
}

.doc-acceptance__ref-row:first-child {
  background: #f8f9fa;
}

.doc-acceptance__ref-label {
  font-weight: 600;
  color: #555;
  font-size: 9pt;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.doc-acceptance__ref-value {
  color: #111;
  font-weight: 600;
}

/* ── Sections (A / B) ── */
.doc-acceptance__section {
  margin-bottom: 24px;
}

.doc-acceptance__section-label {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.doc-acceptance__section-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  color: #fff;
  font-size: 9.5pt;
  font-weight: 700;
  flex-shrink: 0;
}

.doc-acceptance__section-title {
  font-size: 12.5pt;
  font-weight: 700;
  color: #1a1a1a;
}

.doc-acceptance__text {
  font-size: 10pt;
  line-height: 1.7;
  color: #444;
  margin: 0 0 12px 0;
}

/* ── Divider zwischen A und B ── */
.doc-acceptance__divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 4px 0 20px;
  color: #bbb;
  font-size: 9pt;
}

.doc-acceptance__divider::before,
.doc-acceptance__divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #e0e0e0;
}

/* ── Link-Box ── */
.doc-acceptance__link-box {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 12px 16px;
  border: 1px solid #e0e0e0;
  border-left: 4px solid #999;
  border-radius: 4px;
  background: #fafafa;
}

.doc-acceptance__link-label {
  font-size: 9pt;
  font-weight: 700;
  color: #888;
  white-space: nowrap;
  padding-top: 1px;
}

.doc-acceptance__link {
  font-size: 10pt;
  color: #1a1a1a;
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-all;
}

/* ── Unterschrifts-Felder ── */
.doc-acceptance__signatures {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px;
  margin-top: 36px;
  max-width: 560px;
}

.doc-acceptance__sig-field {
  padding-top: 4px;
}

.doc-acceptance__sig-line {
  height: 1px;
  background: #555;
  margin-bottom: 8px;
  margin-top: 52px;
}

.doc-acceptance__sig-label {
  font-size: 9pt;
  color: #777;
}

/* ── CTA-Block (grüner Button unten) ── */
.doc-acceptance__cta {
  padding-top: 20px;
  display: flex;
  align-items: center;
}

.doc-acceptance__btn-accept {
  display: inline-block;
  padding: 13px 30px;
  background: #16a34a;
  color: #fff !important;
  font-size: 11pt;
  font-weight: 700;
  border-radius: 6px;
  text-decoration: none;
  letter-spacing: 0.025em;
  border: none;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Hinweiszeile (nur Unterschrift-Variante) ── */
.doc-acceptance__note {
  font-size: 9.5pt;
  color: #888;
  font-style: italic;
  padding-top: 16px;
  border-top: 1px solid #e4e4e4;
}

@media print {
  .doc-acceptance__ref-row:first-child { background: transparent; }
  .doc-acceptance__link-box { background: transparent; }
  .doc-acceptance__btn-accept {
    background: #16a34a !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    color: #fff !important;
  }
  .doc-acceptance__section-num {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
