/* ===== Grundlayout ===== */
* { box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background-color: #eef1f5; color: #1c1e21; margin: 0; padding: 20px; }
.container { max-width: 1600px; margin: auto; background: #fff; padding: 24px; border-radius: 10px; box-shadow: 0 2px 12px rgba(0,0,0,0.08); position: relative; }
.header-logo { position: absolute; top: 20px; right: 20px; width: 100px; height: 100px; object-fit: contain; }
.copyright { margin-top: 24px; padding: 16px 14px; border-top: 1px solid #e5e7eb; text-align: center; color: #6b7280; font-size: 13px; line-height: 1.7; background: #f8fafc; border-radius: 0 0 10px 10px; }
.copyright-brand { display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 700; color: #334155; }
.copyright-logo { width: 22px; height: 22px; object-fit: contain; }
.copyright a { color: #0f4c81; text-decoration: none; }
.copyright a:hover { text-decoration: underline; }

/* ===== Drucken: nur das geöffnete Dokumenten-Popup ===== */
/* Unterer Seitenrand (55px) hält den Fuß am SEITENBODEN frei vom Inhalt;
   oben/links/rechts 0 → Kopf (thead) ganz oben, randlos. */
@page { margin: 0 0 55px 0; }

@media print {
  /* Alle Geschwister des Modals komplett entfernen (kein Platzverbrauch →
     keine leeren Druckseiten); visibility:hidden würde Platz behalten. */
  body > *:not(#doc-modal) { display: none !important; }
  html, body { height: auto; margin: 0; padding: 0; background: #fff; }
  #doc-modal { position: static; display: block !important; padding: 0; overflow: visible; background: #fff; }
  #doc-modal .modal-dialog { max-height: none; max-width: none; width: 100%; box-shadow: none; border-radius: 0; margin: 0; }
  #doc-modal .modal-body { overflow: visible; padding: 20px; }
  /* Kein "Dokument"-Titel oben links im Ausdruck */
  #doc-modal .modal-header { display: none !important; }
  #doc-modal .modal-close, #doc-modal .print-btn, #doc-modal .modal-logo { display: none !important; }
  #doc-modal .doc-footer { display: block !important; }
  /* DOKUMENTEN-KOPF (thead): wird auf jeder Seite ganz oben wiederholt. */
  #doc-modal .doc-print-layout thead { display: table-header-group; }
  /* DOKUMENTEN-FUSS: fixed am UNTEREN SEITENRAND auf jeder Seite — liegt im
     @page-Unterrand (55px), der Inhalt endet darüber, keine Überlappung. */
  #doc-modal .doc-footline {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 30px;
    box-sizing: border-box;
    padding: 4px 15px;
    background: #fff;
    z-index: 9999;
  }
  /* Sicherung: Inhalt endet oberhalb des Fußes (letzte Seite) */
  #doc-modal .modal-body { padding-bottom: 35px; }
  /* Tabellenüberschriften farblich abgesetzt drucken (auf jeder Seite) */
  .hierarchy-table th {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
h1 { color: #0f4c81; margin: 0 0 4px; font-size: 1.6em; }
.subtitle { color: #6b7280; margin: 0 0 18px; font-size: 13px; }
h2 { color: #0f4c81; border-bottom: 1px solid #e5e7eb; padding-bottom: 8px; font-size: 1.15em; margin-top: 0; }

.controls { display: flex; gap: 14px; align-items: flex-end; margin-bottom: 18px; flex-wrap: wrap; }
.control-group { display: flex; flex-direction: column; }
label { margin-bottom: 5px; font-weight: 600; color: #4b5563; font-size: 13px; }
select, input[type="file"] { font-size: 15px; }
select { padding: 9px; border-radius: 6px; border: 1px solid #cbd5e1; min-width: 200px; }
button { padding: 10px 16px; border-radius: 6px; border: none; font-weight: 600; cursor: pointer; font-size: 14px; }
button.primary { background-color: #0f4c81; color: white; }
button.primary:hover { background-color: #0c3d69; }
button.secondary { background-color: #e5e7eb; color: #1f2937; }
button.secondary:hover { background-color: #d1d5db; }

.editor-container { display: flex; flex-direction: column; gap: 20px; }
/* Validieren-Button direkt unter den EDI-Daten, Dokument anzeigen unter dem Ergebnis */
.validate-btn { align-self: center; margin-top: 12px; padding: 10px 32px; font-size: 15px; }
.doc-btn { align-self: center; margin-top: 14px; padding: 9px 26px; font-size: 14px; }
.panel { flex: 1; display: flex; flex-direction: column; min-width: 0; }
textarea { width: 100%; height: 55vh; padding: 12px; border: 1px solid #cbd5e1; border-radius: 6px; font-family: 'Courier New', Courier, monospace; font-size: 13px; box-sizing: border-box; resize: vertical; white-space: pre; overflow: auto; }
.result-panel { overflow: visible; }
.result-panel .placeholder { color: #9ca3af; text-align: center; font-size: 14px; padding: 40px 10px; }

/* ===== Status-Banner ===== */
.banner { padding: 12px 16px; border-radius: 8px; margin-bottom: 14px; font-weight: 700; font-size: 15px; }
.banner.ok { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.banner.warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.banner.error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.banner .counts { font-weight: 400; font-size: 13px; }

/* ===== Interchange-Karte ===== */
.ic-card { background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 8px; padding: 12px 14px; margin-bottom: 14px; font-size: 13px; }
.ic-card .ic-row { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-bottom: 6px; }
.ic-card .ic-row span b { color: #334155; }
.ic-card .issues { margin-top: 6px; }

/* ===== Ergebnistabelle ===== */
table.result-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.result-table th { background: #0f4c81; color: #fff; text-align: left; padding: 9px 10px; font-weight: 600; white-space: nowrap; }
.result-table td { padding: 9px 10px; border-bottom: 1px solid #e5e7eb; vertical-align: top; }
.result-table tr.msg-row { cursor: pointer; }
.result-table tr.msg-row:hover td { background: #f1f5f9; }
.result-table tr.detail-row > td { background: #f8fafc; padding: 0; }
.result-table .mono { font-family: 'Courier New', Courier, monospace; }

/* Status-Badges */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.badge.ok { background: #d1fae5; color: #065f46; }
.badge.warning { background: #fef3c7; color: #92400e; }
.badge.error { background: #fee2e2; color: #991b1b; }
.badge.test { background: #e0e7ff; color: #3730a3; margin-left: 6px; }

/* Fehler-/Warnungslisten in Tabellenzelle */
.issue-list { margin: 0; padding: 0; list-style: none; }
.issue-list li { margin: 2px 0; padding-left: 16px; position: relative; }
.issue-list li::before { position: absolute; left: 0; font-weight: 700; }
.issue-list li.err::before { content: "✕"; color: #dc2626; }
.issue-list li.warn::before { content: "⚠"; color: #d97706; }
.issue-count { font-size: 12px; color: #6b7280; }
.issue-more { color: #0f4c81; cursor: pointer; text-decoration: underline; font-size: 12px; }

/* Fehler-ab-Zeile-Spalte */
.first-err-line { color: #b91c1c; font-weight: 700; }

/* Expandierbare Segment-Detailansicht (eigene Blöcke unter der Tabelle) —
   komplett expandiert, KEINE innere Scrollbar */
.seg-detail-wrap { margin-top: 10px; border: 1px solid #cbd5e1; border-radius: 8px; background: #fff; }
.seg-detail { padding: 10px 12px; overflow-x: auto; }
.seg-detail-title { font-weight: 700; color: #334155; margin-bottom: 6px; font-size: 13px; }
.seg-detail .seg-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.seg-detail .seg-table th { background: #334155; color: #fff; text-align: left; padding: 5px 8px; white-space: nowrap; }
.seg-detail .seg-table td { padding: 4px 8px; border-bottom: 1px solid #eef2f7; vertical-align: top; }
.seg-detail td.line { color: #9ca3af; width: 44px; white-space: nowrap; }
/* Segment-String komplett OHNE Umbruch (bei Bedarf horizontal scrollbar) */
.seg-detail td.raw { font-family: 'Courier New', Courier, monospace; white-space: nowrap; word-break: normal; }
.seg-detail td.comment { color: #475569; }
.seg-detail td.befund { width: 30%; }

/* Spalte "Unbrauchbar": schmal, nur "U", dunkelrotes * ab der ersten Fehlerzeile */
.seg-detail th.unbrauchbar { width: 24px; text-align: center; }
.seg-detail td.unbrauchbar { text-align: center; width: 24px; }
.unbrauchbar-mark { color: #7f1d1d; font-weight: 900; font-size: 16px; }

/* Konsistente Zeilenfärbung: Fehlerzeile = Zeile rot markiert, Warnzeile = orange.
   Nur die Segment-Spalte bekommt roten Text; Zeile/Beschreibung bleiben lesbar. */
.seg-detail tr.has-err td { background: #fee2e2; }
.seg-detail tr.has-err td.raw { color: #b91c1c; font-weight: 700; }
.seg-detail tr.has-err td.line, .seg-detail tr.has-err td.comment { color: #374151; }
.seg-detail tr.has-warn td { background: #fef3c7; }
.seg-detail tr.has-warn td.raw { color: #b45309; font-weight: 600; }
.seg-detail tr.has-warn td.line, .seg-detail tr.has-warn td.comment { color: #374151; }
.seg-detail tr.has-err:hover td, .seg-detail tr.has-warn:hover td { filter: brightness(0.97); }

/* Befund-Spalte */
.befund-err { color: #b91c1c; font-weight: 700; }
.befund-warn { color: #b45309; font-weight: 600; }

/* Allgemeine Befunde ohne Zeilenzuordnung */
.gen-issues { margin-top: 10px; padding: 8px 10px; background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 6px; font-size: 12px; }
.gen-issues b { display: block; margin-bottom: 4px; color: #334155; }

/* ===== Segment-Detail-Popup ===== */
.modal-overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.65); display: flex; align-items: flex-start; justify-content: center; padding: 30px 16px; z-index: 1000; overflow-y: auto; }
.modal-dialog { background: #fff; border-radius: 10px; max-width: 1200px; width: 100%; max-height: 85vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,0.35); }
.modal-header { display: flex; justify-content: flex-start; align-items: center; gap: 12px; padding: 10px 16px; background: #0f4c81; color: #fff; border-radius: 10px 10px 0 0; flex-shrink: 0; }
.modal-header h3 { margin: 0; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.modal-logo { width: 30px; height: 30px; object-fit: contain; border-radius: 4px; background: #fff; padding: 2px; margin-left: auto; }
.modal-toggle { display: flex; gap: 0; flex-shrink: 0; margin-left: auto; }
.modal-header .modal-logo { margin-left: auto; }
.modal-header .modal-toggle + .modal-close, .modal-header .modal-logo + .print-btn + .modal-close { margin-left: 0; }
.modal-dialog-wide { max-width: 1500px; }
.print-btn { padding: 6px 14px; border: 1px solid #fff; background: #fff; color: #0f4c81; border-radius: 6px; font-size: 13px; font-weight: 600; cursor: pointer; flex-shrink: 0; }
.print-btn:hover { background: #e8eef5; }
.modal-close { background: none; border: none; color: #fff; font-size: 24px; line-height: 1; cursor: pointer; padding: 0 6px; flex-shrink: 0; }
.modal-close:hover { color: #fecaca; }
.modal-body { padding: 14px 16px; overflow-y: auto; }
/* Äußere DRUCK-Layout-Tabelle: thead-Zeile = DOKUMENTEN-KOPF, tbody =
   Inhalt, tfoot-Zeile = DOKUMENTEN-FUSS. Der Browser wiederholt thead/tfoot
   auf JEDER Druckseite automatisch ÜBER bzw. UNTER dem Inhalt — keine
   Überlappung möglich. In der Bildschirm-Ansicht ausgeblendet. */
.doc-print-layout { width: 100%; border-collapse: collapse; }
.doc-print-layout thead { display: none; }
.doc-print-layout thead td {
  text-align: right;
  font-size: 10px;
  font-weight: 400;
  color: #888;
  background: #fff !important;
  padding: 8px 6px;
  white-space: nowrap;
}
.doc-print-layout .doc-line-logo { height: 18px; width: auto; vertical-align: middle; margin-right: 6px; }
.doc-print-layout thead td span { vertical-align: middle; }
.doc-print-layout .doc-print-body { padding: 0; }
/* DOKUMENTEN-FUSS: Bildschirm ausgeblendet, Ausdruck fixed am SEITENBODEN */
.doc-footline { display: none; }
.doc-footline img { height: 18px; width: auto; vertical-align: middle; margin-right: 6px; }
.doc-footline span { vertical-align: middle; }

/* Einzeln / Alle-Nachrichten-Switch */
.modal-toggle { display: flex; gap: 0; flex-shrink: 0; }
.toggle-btn { padding: 6px 14px; border: 1px solid #fff; background: transparent; color: #fff; font-size: 13px; font-weight: 600; cursor: pointer; }
.toggle-btn:first-child { border-radius: 6px 0 0 6px; }
.toggle-btn:last-child { border-radius: 0 6px 6px 0; }
.toggle-btn.active { background: #fff; color: #0f4c81; }
.toggle-btn:not(.active):hover { background: rgba(255, 255, 255, 0.2); }

/* Alle-Nachrichten-Ansicht */
.all-msg-block { margin-bottom: 18px; }
.all-msg-block:last-child { margin-bottom: 0; }
.all-msg-head { padding: 8px 10px; background: #eef2f7; border: 1px solid #dbe2ea; border-radius: 6px 6px 0 0; font-size: 13px; color: #1f2937; }

/* ===== Dokumentenansicht ===== */
#document-renderer { margin-top: 26px; }
#document-wrapper { background-color: #fff; border: 1px solid #d4d4d4; box-shadow: 0 0 10px rgba(0,0,0,0.1); padding: 40px; overflow-x: auto; }
#document-output { font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; color: #333; font-size: 12px; min-width: 640px; }
#document-output .placeholder { color: #888; text-align: center; font-size: 16px; padding: 60px 0; }
.doc-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 50px; }
.doc-header h3 { font-size: 2.2em; margin: 0; color: #000; }
.doc-header .company-details { text-align: right; font-size: 1em; }
.doc-addresses { display: flex; justify-content: space-between; margin-bottom: 50px; font-size: 1.1em; }
.address-block { width: 48%; }
.address-block strong { display: block; margin-bottom: 5px; }
.doc-meta { display: flex; justify-content: flex-end; margin-bottom: 30px; }
.meta-table { border-collapse: collapse; font-size: 1.1em; }
.meta-table td { padding: 4px 8px; }
.meta-table td:first-child { text-align: right; font-weight: bold; }
.hierarchy-table { width: 100%; border-collapse: collapse; margin-bottom: 30px; font-size: 12px; }
.hierarchy-table th, .hierarchy-table td { border-bottom: 1px solid #eee; padding: 10px 8px; text-align: left; vertical-align: top; }
.hierarchy-table th { background-color: #2c3e50; color: white; font-weight: bold; }
.hierarchy-table td { line-height: 1.5; }
.hierarchy-table tr.package-row td { background-color: #ecf0f1; border-top: 2px solid #bdc3c7; }
.hierarchy-table tr.item-row:hover td { background-color: #fdfdea; }
.hierarchy-table .level-2 { padding-left: 40px !important; }
.hierarchy-table .level-3 { padding-left: 80px !important; }
.hierarchy-table .package-description { font-weight: bold; }
.hierarchy-table .nve-id { font-family: 'Courier New', monospace; font-size: 1.1em; color: #34495e; }
.hierarchy-table .gtin-col { font-family: 'Courier New', monospace; color: #7f8c8d; }
.hierarchy-table .number { text-align: right; }
/* Sammelrechnungs-Tabelle: auf Containerbreite fixieren, damit die Gesamt-Spalte
   exakt am rechten Rand endet und der Summenblock darunter rechts bündig fluchtet */
.sammel-table { width: 100%; table-layout: fixed; }
.sammel-table th:nth-child(1) { width: 12%; }
.sammel-table th:nth-child(2) { width: 9%; }
.sammel-table th:nth-child(3) { width: 9%; }
.sammel-table th:nth-child(4) { width: 12%; }
.sammel-table th:nth-child(5) { width: 12%; }
.sammel-table th:nth-child(6) { width: 14%; }
.sammel-table th:nth-child(7) { width: 11%; }
.sammel-table th:nth-child(8) { width: 10%; }
.sammel-table th:nth-child(9) { width: 11%; }
.sammel-table th.number, .sammel-table td.number { white-space: nowrap; }

/* Summenzeile der Sammelrechnung (in der Tabelle, unter Netto/USt/Gesamt) */
.sammel-sum-row td { border-top: 2px solid #000; font-weight: 700; background: #f8fafc; }
.sammel-sum-row td.number { text-align: right; }
.sammel-sum-label { text-align: right; }

/* Summenblock der Sammelrechnung: ganz rechts bündig unterhalb der Tabelle,
   Schrift in gleicher Größe und Fett wie die Summenzeile der Tabelle */
.sammel-summary { margin-top: 18px; }
.sammel-summary .totals-table { width: fit-content; min-width: 280px; margin-left: auto; margin-right: 0; border-collapse: collapse; font-size: 12px; font-family: inherit; }
.sammel-summary .totals-table td { padding: 4px 12px; font-weight: 700; }
.sammel-summary .totals-table td:first-child { text-align: left; white-space: nowrap; }
.sammel-summary .totals-table td:last-child { text-align: right; white-space: nowrap; }
.sammel-summary .totals-table tr.grand-total td { border-top: 2px solid #000; border-bottom: 3px double #000; font-weight: 800; }


.doc-summary { display: flex; justify-content: flex-end; align-items: flex-start; margin-top: 20px; }
.totals-table { width: 350px; border-collapse: collapse; font-size: 1.2em; margin-left: auto; }
.totals-table td { padding: 8px 10px; }
.totals-table tr.grand-total td { border-top: 2px solid #000; border-bottom: 3px double #000; font-weight: bold; }
.totals-table td:first-child { text-align: right; }
.doc-footer { margin-top: 50px; border-top: 1px solid #ccc; padding-top: 15px; font-size: 0.9em; color: #666; text-align: center; }

@media (max-width: 1100px) {
  .editor-container { flex-direction: column; }
  textarea { height: 30vh; }
  .result-panel { max-height: none; }
}

/* GTIN-Auflösung: Link auf Verified by GS1 + Lookup-Ergebnis */
.gtin-cell { white-space: nowrap; }
.gtin-link { color: #1d4ed8; text-decoration: underline dotted; cursor: pointer; }
.gtin-link:hover { color: #1e40af; }
.lookup-info { display: block; font-size: 11px; line-height: 1.3; max-width: 260px; }
.lookup-info.ok { color: #065f46; }
.lookup-info.none { color: #9ca3af; }
.lookup-info.err { color: #b91c1c; }
.gln-link { color: #1d4ed8; text-decoration: underline dotted; cursor: pointer; }
.gln-link:hover { color: #1e40af; }
