:root {
  --primary: #006ea7;
  --primary-dark: #005683;
  --accent: #0cb515;
  --text-main: #1f2933;
  --text-muted: #6b7280;
  --border: #d1d9e6;
  --bg: #f3f5f9;
  --card-bg: #ffffff;
}

/* Basis */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text-main);
}

/* Haupt wrapper - hier die sichtbare Max-Breite definieren */
.wizard-wrapper {
  max-width: 1100px; /* <-- gewünschte Seitenbreite, anpassen */
  margin: 30px auto;
  padding: 0 15px 40px;
  box-sizing: border-box;
}

/* Title / Card */
.page-title {
  text-align: center;
  margin-bottom: 25px;
  font-size: 1.8rem;
  color: var(--primary);
}

.card {
  background: var(--card-bg);
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.08);
  padding: 25px 30px 30px;
  margin-bottom: 20px;
}

/* Step Indicator */
.step-indicator {
  display: flex;
  justify-content: space-between;
  margin-bottom: 20px;
  padding: 0 10px;
}

.step-indicator-item {
  flex: 1;
  text-align: center;
  position: relative;
}

.step-indicator-item::after {
  content: "";
  position: absolute;
  top: 17px;
  left: 50%;
  width: 100%;
  height: 2px;
  background: #dbe3f0;
  z-index: 0;
}

.step-indicator-item:last-child::after {
  display: none;
}

.step-circle {
  position: relative;
  z-index: 1;
  margin: 0 auto 6px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid #dbe3f0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-weight: 600;
  background: #fff;
}

.step-label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.step-indicator-item.active .step-circle {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.step-indicator-item.active .step-label {
  color: var(--primary);
  font-weight: 600;
}

/* Form Steps */
.form-step {
  display: none;
}

.form-step.active {
  display: block;
}

.section-title {
  font-size: 1.2rem;
  margin: 5px 0 10px;
  color: var(--text-main);
}

.section-subtitle {
  margin-top: 0;
  font-size: 0.95rem;
  color: var(--text-muted);
}

.subsection-title {
  margin-top: 25px;
  font-size: 1rem;
  color: var(--text-main);
}

/* Basic fields */
.form-group {
  margin-bottom: 15px;
}

.form-group label {
  display: block;
  margin-bottom: 4px;
  font-weight: 600;
  font-size: 0.9rem;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 9px 10px;
  border-radius: 4px;
  border: 1px solid var(--border);
  font-size: 0.95rem;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(0, 110, 167, 0.15);
}

/* Two columns */
.two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

/* Privat/Firma Toggle */
.entity-toggle {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 10px 0 20px;
}

.entity-option {
  border-radius: 6px;
  border: 1px solid var(--border);
  padding: 10px 15px;
  text-align: center;
  cursor: pointer;
  background: #f9fafb;
  font-weight: 600;
  color: var(--text-muted);
}

.entity-option input {
  display: none;
}

.entity-option.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(0, 110, 167, 0.15);
  background: #fff;
  color: var(--primary);
}

/* Paketbereich */
.package-counter {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0 20px;
}

.package-counter input {
  width: 80px;
  text-align: center;
  padding: 7px 5px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.btn-icon {
  width: 32px;
  height: 32px;
  border-radius: 4px;
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}

.btn-icon:hover {
  background: var(--primary-dark);
}

#packagesContainer {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.package-card {
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #f9fbff;
  padding: 14px 16px 10px;
}

.package-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.package-title {
  font-weight: 700;
  letter-spacing: 0.03em;
  font-size: 0.9rem;
  text-transform: uppercase;
}

.package-weight-total {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-right: auto;
  margin-left: 10px;
}

.package-remove {
  border: none;
  background: transparent;
  color: #e3342f;
  cursor: pointer;
  font-size: 1rem;
  margin-left: 8px;
}

.package-body {
  border-top: 1px solid #e2e8f0;
  padding-top: 10px;
}

/* Warnbox */
.weight-warning {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: #fff7e6;
  border: 1px solid #ffecb5;
  color: #7c5700;
  border-radius: 4px;
  padding: 8px 10px;
  font-size: 0.85rem;
  margin-bottom: 10px;
}

.weight-warning .icon {
  font-weight: 700;
  margin-top: 1px;
}

/* Artikelzeilen */
.article-row {
  display: grid;
  grid-template-columns: 3fr 1.6fr auto;
  gap: 12px;
  align-items: end;
}

.article-row .form-group {
  margin-bottom: 8px;
}

.article-row .remove-item {
  align-self: center;
  margin-bottom: 8px;
  border-radius: 4px;
  border: none;
  background: #f87171;
  color: #fff;
  font-size: 0.8rem;
  padding: 6px 8px;
  cursor: pointer;
}

.article-row .remove-item:hover {
  background: #e3342f;
}

.add-item-btn {
  margin-top: 10px;
  padding: 7px 10px;
  border-radius: 4px;
  border: 1px solid var(--primary);
  background: #fff;
  color: var(--primary);
  font-size: 0.85rem;
  cursor: pointer;
}

.add-item-btn:hover {
  background: #eef7ff;
}

/* Buttons */
.step-buttons {
  margin-top: 20px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.btn-primary,
.btn-secondary {
  padding: 9px 18px;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  background: #e5e7eb;
  color: #374151;
}

.btn-secondary:hover {
  background: #d1d5db;
}

/* Output cards / success area */
.hidden {
  display: none;
}

.success-header {
  border-radius: 6px 6px 0 0;
  border: 1px solid #d1fae5;
  background: #ecfdf3;
  padding: 10px 14px;
  margin: -5px -5px 15px;
}

.success-title {
  color: #047857;
  font-weight: 700;
  margin-bottom: 4px;
}

.success-subtitle {
  font-size: 0.9rem;
  color: #166534;
}

.download-hint {
  display: flex;
  border-radius: 6px;
  border: 1px solid #dbeafe;
  background: #eff6ff;
  padding: 10px 14px;
  font-size: 0.9rem;
  margin-bottom: 15px;
}

.hint-icon {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 10px;
  font-weight: 700;
}

.hint-title {
  font-weight: 700;
  margin-bottom: 4px;
}

.center-actions {
  text-align: center;
  margin-bottom: 15px;
}

/* Kaufbeleg drucken – blau & sichtbar */
.btn-download {
  padding: 10px 22px;
  border-radius: 999px;
  border: none;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.95rem;
}

.btn-download:hover {
  background: var(--primary-dark);
  color: #fff;
}

/* Kaufbeleg-Seiten */
#belegSheets {
  margin-top: 20px;
}

.beleg-sheet {
  background: #fff;
  border: 1px solid #d1d5db;
  margin: 0 auto 25px;
  padding: 25px 30px;
  max-width: 800px;
  box-sizing: border-box;
}

.beleg-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 12px;
}

.beleg-header-left {
  font-size: 1.2rem;
  font-weight: 700;
}

.beleg-header-right {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Row: Firmenkasten + Barcode */
.beleg-main-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 12px;
}

.beleg-main-box {
  flex: 1.1;
  border-radius: 16px;
  border: 3px solid #000;
  padding: 14px 18px;
  text-align: center;
}

.beleg-main-title {
  font-size: 1rem;
  margin-bottom: 4px;
}

.beleg-main-company {
  font-size: 1.2rem;
  font-weight: 700;
}

.beleg-main-address {
  font-size: 0.9rem;
}

.beleg-main-barcode {
  flex: 0.9;
  text-align: center;
  font-size: 0.8rem;
}

/* Warnhinweis */
.beleg-warning {
  font-size: 0.8rem;
  margin-bottom: 10px;
}

/* Spalten Ident + Bankdaten */
.beleg-columns {
  display: grid;
  grid-template-columns: 1.4fr 1.4fr;
  gap: 30px;
  margin-top: 8px;
}

.beleg-col-title {
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 4px;
}

/* Label + Wert in einer Zeile */
.field-block {
  margin-bottom: 3px;
  font-size: 0.85rem;
  display: flex;
  align-items: baseline;
}

.field-label {
  font-weight: 600;
  min-width: 100px;
  margin-right: 4px;
}

.field-value {
  flex: 1;
}

/* Artikel Tabelle */
.item-table {
  margin-top: 20px;
  margin-bottom: 50px;
  border-collapse: collapse;
  width: 100%;
  font-size: 0.85rem;
}

.item-table th,
.item-table td {
  border: 1px solid #d1d5db;
  padding: 4px 6px;
}

.item-table th {
  background: #f3f4f6;
}

/* Eigentumserklärung / Unterschrift */
.beleg-footer {
  margin-top: 10px;
  font-size: 0.8rem;
}

.signature-section {
  display: grid;
  grid-template-columns: 1.4fr 1.2fr;
  gap: 30px;
  margin-top: 5px;
}

.signature-section p {
  margin: 0 0 6px;
  text-align: justify;
}

.signature-section .sig-right {
  margin-top: 25px;
}

.signature-section .sig-right .sig-row {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}

.sig-row span:first-child {
  width: 95px;
}

.sig-line {
  flex: 1;
  border-bottom: 1px solid #111827;
  display: block;
  min-height: 18px;
}

/* Footer / abtrennbarer Teil */
.cut-line {
  border-top: 1px dashed #9ca3af;
  margin: 16px 0 10px;
  position: relative;
  text-align: center;
  font-size: 0.75rem;
  color: #6b7280;
}

.cut-line::before,
.cut-line::after {
  content: "✂";
  position: absolute;
  top: -10px;
  font-size: 0.9rem;
}

.cut-line::before {
  left: 0;
}

.cut-line::after {
  right: 0;
}

.bottom-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
}

.bottom-label-left {
  border: 1px solid #000;
  padding: 6px 10px;
}

.bottom-label-right {
  text-align: right;
}

.bottom-label-right .label-title {
  font-weight: 700;
}

.barcode {
  width: 260px;
  height: 60px;
}

/* Responsive */
@media (max-width: 768px) {
  .wizard-wrapper {
    margin-top: 15px;
  }

  .card {
    padding: 18px 16px 20px;
  }

  .step-indicator {
    flex-direction: column;
    gap: 8px;
  }

  .step-indicator-item::after {
    display: none;
  }

  .two-col {
    grid-template-columns: 1fr;
  }

  .article-row {
    grid-template-columns: 1fr;
  }

  .beleg-sheet {
    padding: 18px 15px;
  }

  .beleg-main-row {
    flex-direction: column;
  }

  .beleg-columns {
    grid-template-columns: 1fr;
  }

  .signature-section {
    grid-template-columns: 1fr;
  }

  .bottom-label {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
}

/* --- OPTIMIERTE DRUCK-STYLES (Ersetzt alle vorherigen @media print Blöcke) --- */

/* 1. Reset der Seitenränder: Wir übernehmen die Kontrolle */
@page {
  size: A4 portrait;
  margin: 0mm; /* Entfernt Browser-Header/Footer und Ränder */
}

@media print {
  /* 2. Globaler Reset für den Druckkontext */
  html, body {
    width: 210mm;
    height: 297mm;
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
  }

  /* 3. Ausblenden ALLER UI-Elemente */
  .wizard-wrapper > *:not(#belegWrapper), /* Versteckt alles im Wrapper außer dem Beleg */
  .page-title,
  .step-indicator,
  #wizardCard,
  .success-header,
  .download-hint,
  .center-actions,
  .btn-download,
  .cut-line::before, /* Sonderzeichen können Layout stören */
  .cut-line::after {
    display: none !important;
  }

  /* 4. Wrapper sichtbar machen und resetten */
  .wizard-wrapper,
  #belegWrapper {
    display: block !important;
    visibility: visible !important;
    position: absolute;
    top: 0;
    left: 0;
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    max-width: none !important;
    box-shadow: none !important;
    border: none !important;
  }

  /* 5. Das eigentliche Blatt Papier (A4) */
  .beleg-sheet {
    position: relative;
    width: 210mm !important; /* Exakt A4 Breite */
    min-height: 297mm !important; /* Exakt A4 Höhe */
    margin: 0 !important;
    /* 15mm Innenabstand sorgt für Sicherheit bei Druckern, die nicht randlos drucken können */
    padding: 15mm !important; 
    box-sizing: border-box !important; /* WICHTIG: Padding wird in die 210mm eingerechnet */
    border: none !important;
    page-break-after: always !important;
    float: none !important;
    overflow: hidden !important; /* Verhindert Überlauf */
  }

  /* Verhindert leere Seite am Ende */
  .beleg-sheet:last-child {
    page-break-after: auto !important;
  }

  /* Skalierungskorrekturen für Inhalte */
  .beleg-header-left { font-size: 14pt !important; }
  .beleg-main-box { border-width: 2px !important; }
  .item-table { width: 100% !important; font-size: 9pt !important; }
  .barcode { max-width: 100% !important; height: auto !important; }
}
/* --- FIX FÜR MOBILE ANSICHT DES KAUFBELEGS --- */
/* Verhindert, dass der Beleg auf Handys zerquetscht wird */

/* 1. Container scrollbar machen, damit der breite Beleg reinpasst */
#belegSheets {
  width: 100%;
  overflow-x: auto; /* Erlaubt seitliches Scrollen auf dem Handy */
  padding-bottom: 20px;
}

/* 2. Den Beleg zwingen, A4-Breite zu behalten */
.beleg-sheet {
  min-width: 210mm !important; /* Mindestbreite erzwingen */
  width: 210mm !important;
  max-width: none !important;  /* Keine Begrenzung nach oben */
  margin: 0 auto 25px !important;
  box-sizing: border-box !important;
  /* Schriftgröße stabilisieren */
  font-size: 14px !important; 
}

/* 3. Layout-Umbruch auf Mobilgeräten verbieten (Overrides für media-queries) */
.beleg-main-row {
  display: flex !important;
  flex-direction: row !important; /* Immer nebeneinander */
  align-items: center !important;
}

.beleg-columns {
  display: grid !important;
  grid-template-columns: 1.4fr 1.4fr !important; /* Immer 2 Spalten */
  gap: 30px !important;
}

.signature-section {
  display: grid !important;
  grid-template-columns: 1.4fr 1.2fr !important; /* Immer 2 Spalten */
}

.bottom-label {
  display: flex !important;
  flex-direction: row !important;
  justify-content: space-between !important;
}

/* Tabellen aufhübschen */
.item-table {
  font-size: 12px !important;
}
.item-table th, .item-table td {
  white-space: normal !important;
}
/* QR-Code Anpassung */
.beleg-main-barcode {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.qrcode {
  /* Stellt sicher, dass der QR Code scharf bleibt aber nicht das Layout sprengt */
  max-width: 110px;
  height: auto;
}