/* BSR E-Rechnung-Tool – App Mode nach BSR Design Guide */

:root {
  /* Brand Override */
  --brand-primary: #575e66;
  --brand-accent: #f7a723;
  --brand-accent-hover: #d89216;
  --brand-accent-soft: #fff8ec;
  --brand-focus: rgba(247, 167, 35, 0.22);
  --brand-sidebar-hover: rgba(247, 167, 35, 0.18);

  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e0e3e8;
  --border-strong: #c9ced6;

  --text: #171c26;
  --muted: #667085;
  --muted-strong: #475569;

  --accent: var(--brand-accent);
  --accent-hover: var(--brand-accent-hover);
  --accent-soft: var(--brand-accent-soft);

  --success: #059669;
  --success-soft: #ecfdf5;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --warning: var(--brand-accent);
  --warning-soft: #fff8ec;

  --slate: var(--brand-primary);

  --radius-sm: 3px;
  --radius: 4px;
  --radius-pill: 999px;

  --shadow: 0 2px 10px rgba(15, 23, 42, 0.045);
  --shadow-md: 0 10px 28px rgba(15, 23, 42, 0.075);

  --font: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --focus-ring: 0 0 0 3px var(--brand-focus);
}

*, *::before, *::after { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea { font: inherit; }

[hidden] { display: none !important; }

.muted { color: var(--muted); font-weight: 400; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.icon {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

/* ---------- Topbar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--slate);
  color: #fff;
  box-shadow: 0 6px 20px rgba(87, 94, 102, 0.18);
}

.topbar-inner {
  max-width: 1280px;
  min-height: 58px;
  margin: 0 auto;
  padding: 0 28px;
  display: flex;
  align-items: center;
  gap: 28px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  font-size: 15px;
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.4px;
}

.brand-text { font-weight: 500; }
.brand-text strong { font-weight: 800; }

.tabs {
  display: flex;
  align-self: stretch;
  gap: 4px;
}

.tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
  border: 0;
  background: transparent;
  color: rgba(255, 255, 255, 0.75);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.tab:hover { color: #fff; background: var(--brand-sidebar-hover); }

.tab.active { color: #fff; }
.tab.active::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 0;
  height: 3px;
  background: var(--accent);
}

.tab:focus-visible { outline: none; box-shadow: inset var(--focus-ring); }

.topbar-badge {
  margin-left: auto;
  padding: 4px 12px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

/* ---------- Layout ---------- */

.content {
  flex: 1;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 22px 28px 28px;
}

.page {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.page-title {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.4px;
}

.page-subtitle {
  margin-top: 2px;
  color: var(--muted);
}

.page-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 32px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  font: 500 12px/1.2 var(--font);
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}

.btn-sm { min-height: 28px; padding: 5px 10px; }
.btn-icon { min-height: 28px; width: 28px; padding: 0; font-size: 16px; line-height: 1; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-secondary {
  background: var(--surface);
  border-color: var(--border);
  color: var(--muted-strong);
}
.btn-secondary:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent-hover);
  background: var(--accent-soft);
}

.btn-danger {
  background: var(--surface);
  border-color: #f3c4c4;
  color: var(--danger);
}
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); border-color: var(--danger); }

.btn-ghost {
  background: transparent;
  color: var(--muted);
}
.btn-ghost:hover:not(:disabled) { color: var(--danger); background: var(--danger-soft); }

.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn .spinner { width: 12px; height: 12px; }

/* ---------- Segmented ---------- */

.segmented {
  display: inline-flex;
  padding: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.segmented button {
  min-height: 26px;
  padding: 3px 12px;
  border: 0;
  border-radius: 2px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.segmented button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12);
}

.segmented button:focus-visible { outline: none; box-shadow: var(--focus-ring); }

/* ---------- Dropzone ---------- */

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 150px;
  padding: 24px;
  background: var(--surface);
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.dropzone:hover,
.dropzone:focus-within,
.dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.dropzone.compact { min-height: 64px; flex-direction: row; gap: 10px; padding: 14px; }
.dropzone.compact .dropzone-hint { display: none; }
.dropzone.compact .dropzone-icon { width: 20px; height: 20px; margin: 0; }

.dropzone-icon {
  width: 30px;
  height: 30px;
  margin-bottom: 6px;
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.dropzone-title { color: var(--text); font-size: 14px; font-weight: 600; }
.dropzone-title u { color: var(--accent-hover); text-underline-offset: 2px; }
.dropzone-hint { font-size: 12px; }

/* ---------- Panel ---------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-header {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.panel-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted-strong);
}

.panel-body { padding: 16px; }

.panel-footer {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px 24px;
  padding: 12px 16px;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
}

/* ---------- Forms ---------- */

.form-grid { display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field-inline { flex-direction: row; align-items: center; gap: 8px; }
.field-inline .input { width: 260px; }

.field-row { display: flex; align-items: center; gap: 12px; }
.field-row.two { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: end; }
.field-row .input { flex: 1; }

.field-label { color: var(--muted-strong); font-size: 12px; font-weight: 600; }

.suffix { color: var(--muted); font-weight: 600; }

.input, .select {
  width: 100%;
  min-height: 34px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: 600 13px/1.2 var(--font);
  padding: 8px 10px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input:focus, .select:focus { border-color: var(--accent); box-shadow: var(--focus-ring); }
.input:disabled, .select:disabled { background: var(--surface-2); color: var(--muted); cursor: not-allowed; }

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

.check input, input[type="range"] { accent-color: var(--accent); }
.check input { width: 15px; height: 15px; margin: 0; flex-shrink: 0; }
.panel-footer .check { white-space: normal; }

input[type="range"] { width: 100%; margin: 6px 0 0; }

/* ---------- Table ---------- */

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
}

.table { width: 100%; border-collapse: collapse; font-size: 13px; }

.table th {
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
}

.table td {
  white-space: nowrap;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
}

.table tbody tr:hover td { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }

.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; width: 1%; }
.table td.name { max-width: 420px; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }

.table tfoot td {
  background: var(--surface-2);
  font-weight: 600;
  border-top: 1px solid var(--border-strong);
  border-bottom: 0;
}

.saving-good { color: var(--success); font-weight: 700; }

/* ---------- Badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 20px;
  border-radius: var(--radius);
  padding: 2px 9px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
}

.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-warning { background: var(--warning-soft); color: #92400e; }
.badge-muted { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }

.spinner {
  width: 10px;
  height: 10px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Notice ---------- */

.notice {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--accent-soft);
  border: 1px solid #f5d9a8;
  border-radius: var(--radius);
  color: #7c4a03;
  font-weight: 500;
}

.notice-icon {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  flex-shrink: 0;
}

/* ---------- Footer & Toasts ---------- */

.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 24px;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  padding: 14px 28px 22px;
  color: var(--muted);
  font-size: 12px;
}

.toast-stack {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(380px, calc(100vw - 40px));
}

.toast {
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--success);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  font-weight: 500;
  animation: toast-in 0.18s ease-out;
}
.toast.error { border-left-color: var(--danger); }

@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* ---------- Link zur Startseite bsr-tools.de ---------- */

.topbar-home {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 4px 10px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}
.topbar-home:hover { background: var(--brand-sidebar-hover); border-color: var(--accent); text-decoration: none; }
.topbar-home:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.topbar-home + .topbar-badge { margin-left: -16px; }


/* ---------- E-Rechnung-Tool ---------- */

:root { --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace; }

.mono { font-family: var(--mono); font-size: 12px; }
.select-sm { width: auto; min-height: 32px; padding: 6px 28px 6px 10px; font-size: 12px; font-weight: 500; color: var(--muted-strong); }
.results { display: flex; flex-direction: column; gap: 16px; }
.table-scroll { overflow-x: auto; }
.empty { padding: 24px 16px; color: var(--muted); text-align: center; }

.notice .spinner { width: 14px; height: 14px; color: var(--accent-hover); }

/* Ergebnis */
.verdict {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 5px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.verdict.valid { border-left-color: var(--success); }
.verdict.warn { border-left-color: var(--warning); }
.verdict.invalid { border-left-color: var(--danger); }

.verdict-icon {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  color: #fff;
  font-size: 28px;
  font-weight: 800;
  background: var(--muted);
}
.verdict.valid .verdict-icon { background: var(--success); }
.verdict.warn .verdict-icon { background: var(--warning); }
.verdict.invalid .verdict-icon { background: var(--danger); }

.verdict-title { margin: 0; font-size: 22px; font-weight: 800; line-height: 1.2; }
.verdict-sub { margin-top: 3px; color: var(--muted-strong); overflow-wrap: anywhere; }
.verdict-counts { display: flex; gap: 18px; text-align: center; }
.count-value { display: block; font-size: 26px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.count-label { color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: 0.4px; text-transform: uppercase; }
.count-value.danger { color: var(--danger); }
.count-value.warning { color: #b7791f; }

/* Kennzahlen */
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin: 0; background: var(--surface); }
.facts > div { padding: 12px 16px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); min-width: 0; }
.facts dt { color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: 0.4px; text-transform: uppercase; }
.facts dd { margin: 2px 0 0; font-weight: 600; overflow-wrap: anywhere; }

/* Meldungen */
.msg-list { list-style: none; margin: 0; padding: 0; }
.msg {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 10px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
}
.msg:last-child { border-bottom: 0; }
.msg-dot {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  margin-top: 1px;
  border-radius: 50%;
  color: #fff;
  font-size: 11px;
  font-weight: 800;
}
.msg.error .msg-dot { background: var(--danger); }
.msg.warning .msg-dot { background: var(--warning); }
.msg.info .msg-dot { background: var(--muted); }
.msg-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; }
.msg-title { font-weight: 600; }
.msg-code { font: 600 11px/18px var(--mono); padding: 0 6px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); color: var(--muted-strong); white-space: nowrap; }
.msg-official { display: block; margin-top: 3px; color: var(--muted-strong); font-size: 12px; overflow-wrap: anywhere; }
.msg-fields { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.msg-field { font-size: 11px; padding: 1px 7px; border-radius: var(--radius); background: var(--accent-soft); color: #7c4a03; border: 1px solid #f5d9a8; }
.msg-loc { display: block; margin-top: 4px; color: var(--muted); font: 11px/1.4 var(--mono); overflow-wrap: anywhere; }
.msg-group-title { padding: 7px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border); color: var(--muted-strong); font-size: 11px; font-weight: 700; letter-spacing: 0.4px; text-transform: uppercase; }

/* Stapel */
.batch-table tbody tr { cursor: pointer; }
.batch-table tbody tr.selected td { background: var(--accent-soft); }
.batch-table td.file { max-width: 280px; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }

/* Rechnungsansicht */
.viewer-host { display: block; background: #fff; }
.viewer-loading { padding: 28px 16px; color: var(--muted); text-align: center; }

/* Erklärungen (abschaltbar) */
.explain { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; font-weight: 400; line-height: 1.45; }
.explain b { color: var(--muted-strong); }
.panel-intro { display: block; margin: 0; padding: 10px 16px; border-bottom: 1px solid var(--border); background: #fcfcfd; color: var(--muted-strong); font-size: 12px; }
body.no-explain .explain { display: none; }
.btn-toggle[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-hover); font-weight: 600; }

/* Glossar */
.glossary summary { cursor: pointer; list-style: none; }
.glossary summary::-webkit-details-marker { display: none; }
.glossary summary:focus-visible { outline: none; box-shadow: inset var(--focus-ring); }
.glossary:not([open]) summary { border-bottom: 0; }
.glossary-toggle::after { content: " ▾"; }
.glossary[open] .glossary-toggle { font-size: 0; }
.glossary[open] .glossary-toggle::after { content: "Zuklappen ▴"; font-size: 13px; }
.glossary-list { display: grid; grid-template-columns: 200px minmax(0, 1fr); margin: 0; }
.glossary-list dt, .glossary-list dd { padding: 9px 16px; border-bottom: 1px solid var(--border); }
.glossary-list dt { font-weight: 700; }
.glossary-list dd { margin: 0; color: var(--muted-strong); }
.glossary-list dt:last-of-type, .glossary-list dd:last-of-type { border-bottom: 0; }

.dropzone.compact { min-height: 64px; flex-direction: row; gap: 10px; padding: 14px; }
.dropzone.compact .dropzone-hint { display: none; }
.dropzone.compact .dropzone-icon { width: 20px; height: 20px; margin: 0; }

/* ---------- Mobile ---------- */

@media (max-width: 768px) {
  .topbar-inner { flex-wrap: wrap; gap: 0 16px; padding: 0 16px; }
  .brand { min-height: 52px; }
  .topbar-badge { display: none; }
  .topbar-home { order: 2; }
  .content { padding: 18px 16px; }
  .page-header { flex-direction: column; }
  .page-actions { justify-content: flex-start; }
  .footer { padding: 14px 16px 22px; }
  .verdict { grid-template-columns: 44px minmax(0, 1fr); align-items: start; padding: 14px; }
  .verdict-icon { width: 44px; height: 44px; font-size: 22px; }
  .verdict-counts { grid-column: 1 / -1; justify-content: flex-start; }
  .glossary-list { grid-template-columns: 1fr; }
  .glossary-list dt { padding-bottom: 0; border-bottom: 0; }
}

/* ---------- Drucken: Prüfbericht und Rechnungsansicht ---------- */

@media print {
  @page { margin: 14mm; }
  body { background: #fff; font-size: 11px; }
  .topbar, .page-header .page-actions, .dropzone, #engine-status, #batch-panel, .glossary, .footer, .toast-stack, .no-print { display: none !important; }
  .content { padding: 0; max-width: none; }
  .page-header { padding-bottom: 8px; }
  .panel, .verdict { box-shadow: none; break-inside: avoid-page; }
  .msg { break-inside: avoid; }
  .viewer-panel { break-before: page; }
}
